本文介绍了在PHP中将时区设置为UTC(0)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么这样工作?
date_default_timezone_set('Australia/Currie');但这似乎没有任何效果?
But this doesn't seem to take any effect at all?
date_default_timezone_set('UTC');将时区设置为UTC时,此值不会更改:
This value doesn't change when setting the timezone to UTC:
echo date('Y-m-d H:i:s', time());我使用的是php 5.2.13,而我的服务器的时区是:
I'm using php 5.2.13, and the timezone of my server is:
$server_tz = date_default_timezone_get(); echo $server_tz; //outputs 'America/Guayaquil'这是原始代码:
echo time() . "<br>\n"; date_default_timezone_set('UTC'); echo time() . "<br>\n";输出:
1317235130 1317235130推荐答案
问题是您显示的是 time(),这是基于GMT / UTC的UNIX时间戳。那就是为什么它不会改变。 date()另一方面,格式基于该时间戳的时间。
The problem is that you're displaying time(), which is a UNIX timestamp based on GMT/UTC. That’s why it doesn’t change. date() on the other hand, formats the time based on that timestamp.
A 时间戳是自Unix Epoch(1970年1月1日00:00:00 GMT)以来的秒数。
A timestamp is the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT).
echo date('Y-m-d H:i:s T', time()) . "<br>\n"; date_default_timezone_set('UTC'); echo date('Y-m-d H:i:s T', time()) . "<br>\n";更多推荐
在PHP中将时区设置为UTC(0)
发布评论