开发者

PHP date_default_timezone_set makes no change to the time() - why?

Why when I use date_default_timezone_set() does it make no difference to the time() ?

Surely I would expect the values of $server_time and $local_time, below, to be different?

$server_time = time();
date_default_timezone_set('Pacific/Guam');
$local_time = time();
print_r(get_defined_vars());

-------
/* echoe开发者_开发技巧d output */
Array
(
    [server_time] => 1314261374
    [local_time] => 1314261374
)


A timestamp is always without any timezone information. If you use date you see the difference:

$server_time=date(DATE_W3C);
date_default_timezone_set('Pacific/Guam');
$local_time=date(DATE_W3C);
print_r(get_defined_vars());

----
/* echoed output */
Array
(
    [server_time] => 2011-08-25T10:49:26+02:00
    [local_time] => 2011-08-25T18:49:26+10:00
)


time() is timezone independant.


time() returns the current Unix timestamp. If it depends the timezone, the programmers will be get crazy.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜