This article introduces the solution to the inconsistency between the time obtained by PHP date() and time() and the local time. If necessary, you can refer to the solution
Add it in the program
Use
in the header of the page
The code is as follows
代码如下 |
复制代码 |
date_default_timezone_set()设置我的默认时区为北京时间
date_default_timezone_set('PRC');
echo date('Y-m-d H:i:s');
第一种解决方法:
|
|
Copy code
|
代码如下 |
复制代码 |
date_default_timezone_set('PRC'); //设置本地时区
|
date_default_timezone_set() sets my default time zone to Beijing time
date_default_timezone_set('PRC');
echo date('Y-m-d H:i:s');
First solution:
Set the default time zone in the program.
The code is as follows |
Copy code |
|
date_default_timezone_set('PRC'); //Set the local time zone
Second solution:
Modify php.ini and change the "date.timezone" item to "date.timezone = PRC"
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)
And Singapore: Asia/Singapore
Other available values are: Etc/GMT-8, Singapore, Hongkong, PRC
Note: PRC is the People’s Republic of China
http://www.bkjia.com/PHPjc/628944.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/628944.htmlTechArticleThis article introduces the solution to the inconsistency between the time obtained by PHP date() and time() and the local time, if necessary You can refer to the reference solution and add it to the program. Use the code in the header of the page and copy it as follows...
|