Mazatec
Mazatec

Reputation: 11649

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
)

Upvotes: 0

Views: 355

Answers (3)

xdazz
xdazz

Reputation: 160833

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

Upvotes: 1

mkuckert
mkuckert

Reputation: 181

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
)

Upvotes: 2

Wesley van Opdorp
Wesley van Opdorp

Reputation: 14941

time() is timezone independant.

Upvotes: 2

Related Questions