Home  >  Article  >  Backend Development  >  php date function time is wrong

php date function time is wrong

王林
王林Original
2019-10-09 17:42:043088browse

php date function time is wrong

Get the correct PHP time settings

1. Modify php.ini

Open php.ini, search for date.timezone, remove the semicolon in front, add Asia/Shanghai after =, and restart the apache server.

The disadvantage is that if the program is placed on someone else's server and php.ini cannot be modified, then there is nothing you can do.

2, Add time initialization statement in the program

“date_default_timezone_set("Asia/Shanghai"); ”

This can be set arbitrarily by the programmer.

Time zone identifier, available values ​​in mainland China are: PRC, Asia/Chongqing, Asia/Shanghai, Asia/Urumqi (in order China, Chongqing, Shanghai, Urumqi), Etc/GMT-8 ,Asia/Harbin.

Available in Hong Kong and Taiwan: Asia/Macao, Asia/Hong_Kong, Asia/Taipei (Macau, Hong Kong, Taipei in order) and Singapore: Asia/Singapore.

In this way, the output is Beijing time.

More detailed time zone codes, time zone codes, and time zone index codes timezone_identifier can be found on the official website.

Recommended tutorial: PHP video tutorial

The above is the detailed content of php date function time is wrong. For more information, please follow other related articles on the PHP Chinese website!

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