Home  >  Article  >  Backend Development  >  PHP TimeZone 的有关问题

PHP TimeZone 的有关问题

WBOY
WBOYOriginal
2016-06-13 13:04:22984browse

PHP TimeZone 的问题

自PHP5.0开始,PHP时区默认使用UTC,所以获取系统时间时,时间比中国时间少8个小时。

  解决办法:
1.在PHP.ini文件中修改设置。
 [Date]
 ; Defines the default timezone used by the date functions
 date.timezone = Asia/Shanghai

2.在PHP程序中运行时设置。
date_default_timezone_set("Asia/Shanghai");
?>
3.时区是UTC情况下,在使用时间时多加8*3600秒获取中国时间
echo date("Y-m-d H:i:s",time()+8*3600);
?>

  个人推荐使用第二种方法,如果不能不使用"date_default_timezone_get"或"date_default_timezone_set"时,再使用第三种方法。当然了,如果是自己的服务器,也可以通过设置PHP来设置也是行的。
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn