Home  >  Article  >  php教程  >  PHP中Date获取时间不正确怎么办

PHP中Date获取时间不正确怎么办

WBOY
WBOYOriginal
2016-06-13 12:29:15817browse

今天用echo $showtime=date("Y-m-d H:i:s")获取系统时间时,发现获取的时间与系统的时间不符。

    研究了一番发现,PHP默认设置的时间是以格林威治时区为标准的,所以我们必须把PHP的时区设定改为北京时间。

    操作方法:

打开php.ini文件,一般在PHP的安装根目录下 
找到其中的;date.timezone 
删掉date.timezone前面的分号,并改成date.timezone = PRC 
存盘,并重新启动Apahce服务(有时用Apache的restart功能会有问题,建议先stop然后再start)
    让我们重新检验一下echo $showtime=date("Y-m-d H:i:s")。

    是不是时间恢复正常了?

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