Home > php教程 > php手册 > php time()与date()时间与本地电脑有区别

php time()与date()时间与本地电脑有区别

WBOY
Release: 2016-06-13 09:46:45
Original
1240 people have browsed it

经常会有同学问我为什么php time()与date()时间与本地电脑有区别呢,相关有几个小时啊,仔细计算有8小时之差了,这个就是php date_default_timezone_set时区设置问题了,我们只要简单设置即可。

如果date时间不一致可以使用date_default_timezone_set设置时区:

 代码如下 复制代码
";   //对当前时间进行计算 echo date('Y-m-d H:i:s',time()-600); //减10小时 echo "
";   //时间戳转时间 echo date('Y-m-d H:i:s',1364277600);   //时间转时间戳(仅精确到秒) echo strtotime("2013-03-26 14:00"); echo "
";  

?>

除了上面办法我们还可以在php.ini中设置一个时区,这们以后就不需要程序开加这date_default_timezone_set('Asia/Chongqing');了

 代码如下 复制代码

date.timezone = PRC

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template