简体   繁体   中英

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());

-------
/* echoed output */
Array
(
    [server_time] => 1314261374
    [local_time] => 1314261374
)

time()与时区无关。

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() returns the current Unix timestamp. If it depends the timezone, the programmers will be get crazy.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM