PHP用date()获取的时间和本地时间不一致怎么解决?

PHPz
Release: 2020-09-05 14:06:28
Original
2231 people have browsed it

PHP用date()获取的时间和本地时间不一致怎么解决?

PHP用date()获取的时间和本地时间不一致的原因和解决方法

在PHP中使用“date(Y/n/d H:i)”获取时间和本地的真实时间不同的原因可能是:  

1、没有修改php.ini的配置文件中的默认时区为当前的时区位置  

解决方法:修改php.ini,将“date.timezone”项修改为“date.timezone = PRC”  

2、没有在程序中初始化时区  

解决方法:在程序中声明时区:“date_default_timezone_set(’PRC’);”

实例:

Copy after login

建议采用第二种方法。因为你将网站传到别的服务器上时。那个时间说不定不是北京时间。

更多相关知识,请访问 PHP中文网!!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!