关于PHPdate()函数的一个有关问题

WBOY
Release: 2016-06-13 13:39:16
Original
1219 people have browsed it

关于PHPdate()函数的一个问题
今天在查看php手册的时候 发现date函数可以直接传参数Z,php手册上解释说:date('Z')是时差偏移量的秒数。UTC 西边的时区偏移量总是负的,UTC 东边的时区偏移量总是正的。但是我执行以下代码:

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
<?php echo date('Y-m-d H:i:s',time());//输出 2012-03-26 02:08:56
echo date('Z')/3600; //输入0
?>

Copy after login


按道理说是差了8个小时,date('Z')/3600应该输出8 为什么输出为0呢?

------解决方案--------------------
输出是 8
如果你的时区没有修改的话,那么就应该是 0

echo date('Z')/3600; 
echo gmdate('Z')/3600;
如果两者输出结果一样,则表示你的时间是格林威治时间
------解决方案--------------------
因为你没有设定本地时区,如果你设定了php.ini中的date.timezone或者用date_default_timezone_set()
规定了本地时区,结果就是8了。
------解决方案--------------------
你用的是默认的格林时间。因此 echo date('Z') 偏移返回0
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!