Solution to the problem that the time obtained by date() in php5 is not the current time

WBOY
Release: 2016-07-25 09:04:46
Original
985 people have browsed it
  1. [Date]
  2. ; Defines the default timezone used by the date functions
  3. ;date.timezone =
Copy code

The default is off, just remove the comment and change it to

  1. [Date]
  2. ; Defines the default timezone used by the date functions
  3. date.timezone = PRC
Copy code

where PRC is "People's Republic of China"! Other options can be found in the PHP manual. The Asian region omits Beijing and MGB.

If you do not have permission to modify php.ini, you only need to call date_default_timezone_set(' when calling the time and date function PRC') and that's it! 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) Available in Hong Kong and Taiwan: Asia/Macao, Asia/Hong_Kong, Asia/Taipei (Macau, Hong Kong, Taipei in order) Taiwan can be set to: date.timezone = "Asia//Taipei" And Singapore: Asia/Singapore

Attachment: Solution to the eight-hour time difference in PHP5 The time display of php5.1.2 is 8 hours shorter.

  1. echo date("Y-m-d H:i:s");
  2. ?>
Copy the code

The result is that the difference is 8 hours after my own test.

It turns out that in php5 and above versions, to output the local time (only in China), you can refer to the following writing method:

  1. date_default_timezone_set('Asia/Shanghai');
  2. echo date('Y-m-d H:i:s');
  3. ?>
Copy code

This is also possible :

  1. date_default_timezone_set('Asia/Chongqing');
  2. echo date('Y-m-d H:i:s');
  3. ?>
Copy code

See wonderful Here’s the result: the eight-hour time difference problem was successfully solved.



source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!