php date function time is wrong

王林
Release: 2023-04-07 14:24:01
Original
3089 people have browsed it

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"); ”
Copy after login

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!

Related labels:
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