Home  >  Article  >  Backend Development  >  Solution to why the time obtained by date() in php5 is not the current time_PHP Tutorial

Solution to why the time obtained by date() in php5 is not the current time_PHP Tutorial

WBOY
WBOYOriginal
2016-07-21 15:50:58865browse

The relevant setting is to modify the date.timezone parameter in php.ini:
[Date]
; Defines the default timezone used by the date functions
; date.timezone =

The default is off Yes, just remove the comment and change it to
[Date]
; Defines the default timezone used by the date functions
date.timezone = PRC

where PRC is "中华People's Republic"!
For other options, please refer to the php manual.
However, our capital Beijing is omitted from the Asian region above. I don’t know if the foreigner did it on purpose!

If you do not have permission to modify php.ini, you only need to call date_default_timezone_set('
PRC') when calling the time and date function!
You can also call date_default_timezone_get() to view the current time zone setting!



Regarding XXX, the available values ​​in mainland China are:
Asia/Chongqing, Asia/Shanghai, Asia/Urumqi (in order, Chongqing, Shanghai, Urumqi)
Hong Kong and Taiwan Available regions: Asia/Macao, Asia/Hong_Kong, Asia/Taipei (Macau, Hong Kong, Taipei in order)
Taiwan region can be set to: date.timezone = "Asia//Taipei"
Also Singapore: Asia /Singapore


Solution to the eight-hour time difference in PHP5


After installing php5, I accidentally saw someone on the forum saying php5.1.2 The time display is 8 hours shorter,
echo date("Y-m-d H:i:s");
?>
The result of my own test is that the difference is indeed 8 hours.

Later, after searching for information on the forum, the result was finally solved. In php5 and above versions, to output the local time (only in China)
, you can write the code like this:
date_default_timezone_set('Asia/Shanghai');
echo date('Y-m-d H:i:s');
?>

You can also write code like this:
date_default_timezone_set('Asia/Chongqing');
echo date('Y-m-d H:i:s');
?>

This way the time is eight hours apart The problem is solved!!~~~

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/319250.htmlTechArticleThe relevant setting is to modify the date.timezone parameter in php.ini: [Date] ;Definesthedefaulttimezoneusedbythedatefunctions ;date.timezone= The default is off, just remove the comment and change it to...
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