假如一个网站面临国际人群,那么可能分布在不同的时区,那么最好存入UTC时间在数据库,然后读出来以后,根据人群的位置,进行计算时间(月小升认为输出的还是UTC时间,但是要进行后处理,根据读者的时区用JS 来重新输出时间,就可以实现国际化了)
';
date_default_timezone_set("UTC");
$time1 = date("Y-m-d H:i:s");
$times1 = strtotime($time1);
echo time()."
";
echo "UTC时间:".$time1." - ".$times1."
";
date_default_timezone_set("PRC");
$time1 = date("Y-m-d H:i:s");
$times1 = strtotime($time1);
echo "北京时间:".$time1." - ".$times1."
";
echo "当前时区:".date_default_timezone_get()."
";
date_default_timezone_set("Etc/GMT+8");
$time1 = date("Y-m-d H:i:s");
$times1 = strtotime($time1);
echo "+8区时间:".$time1." - ".$times1."
";
date_default_timezone_set("Etc/GMT-8");
$time1 = date("Y-m-d H:i:s");
$times1 = strtotime($time1);
echo "-8区时间:".$time1." - ".$times1."
";
date_default_timezone_set("Etc/GMT+0");
$time = '1501829643';
$stime = strftime( "%Y-%m-%d %H:%M:%S" ,$time)."
";
echo $stime;
date_default_timezone_set("Etc/GMT-8");
$time = '1501829643';
$stime = strftime( "%Y-%m-%d %H:%M:%S" ,$time)."
";
echo $stime;
?>
1501829643
UTC时间:2017-08-04 06:54:03 - 1501829643
北京时间:2017-08-04 14:54:03 - 1501829643
当前时区:PRC
+8区时间:2017-08-03 22:54:03 - 1501829643
-8区时间:2017-08-04 14:54:03 - 1501829643
1501829643 做成字符串存入数据库,读取的时候
date_default_timezone_set("Etc/GMT+0");
2017-08-04 06:54:03
date_default_timezone_set("Etc/GMT-8");
2017-08-04 14:54:03
JS转化国际化时间
You must be logged in to post a comment.
使身体处在一种自然舒适的状态下,让人们倍感高科技带来的舒适与放松!
Java-er也被PHP迷倒了么?哈哈