标签:
1,函数ini_set()设置时区:
可以在文件开头加入 ini_set(‘date.timezone‘,‘Asia/Shanghai‘); // ‘Asia/Shanghai‘ 为上海时区
2,date_default_timezone_set(‘Asia/Shanghai‘);
3,手动修改php.ini设置
打开php找到date.timezone = "PRC" 如有去掉前面的分号,没有的话手动添加!
date()
strtotime()
time()
gmdate()
<?php $time = time(); $value = ‘PRC‘; date_default_timezone_set($value); echo date(‘Y-m-d H:i:s‘,$time),"\n"; echo gmdate(‘Y-m-d H:i:s‘,$time),"\n"; var_dump(date_default_timezone_get()); $value = ‘Asia/Chongqing‘; date_default_timezone_set($value); echo date(‘Y-m-d H:i:s‘,$time),"\n"; echo gmdate(‘Y-m-d H:i:s‘,$time),"\n"; var_dump(date_default_timezone_get()); $value = ‘Asia/Shanghai‘; date_default_timezone_set($value); echo date(‘Y-m-d H:i:s‘,$time),"\n"; echo gmdate(‘Y-m-d H:i:s‘,$time),"\n"; var_dump(date_default_timezone_get()); $value = ‘Europe/Riga‘; date_default_timezone_set($value); echo date(‘Y-m-d H:i:s‘,$time),"\n"; echo gmdate(‘Y-m-d H:i:s‘,$time),"\n"; var_dump(date_default_timezone_get()); ?>
2015-10-12 12:13:51 2015-10-12 04:13:51 string(3) "PRC" 2015-10-12 12:13:51 2015-10-12 04:13:51 string(14) "Asia/Chongqing" 2015-10-12 12:13:51 2015-10-12 04:13:51 string(13) "Asia/Shanghai" 2015-10-12 07:13:51 2015-10-12 04:13:51 string(11) "Europe/Riga"
标签:
原文地址:http://my.oschina.net/u/242853/blog/515789