Reputation: 63
I have tested this code
<?php
//date_default_timezone_set('Europe/Helsinki');
//date_default_timezone_set('Europe/London');
date_default_timezone_set("America/New_York");
$date1 = date("Y-m-d");
$unixDate=time();
echo '[{ "DATE" : "'.$date1.'"},{ "UNIXTIME" : "'.$unixDate.'" }]';
?>
in several sites (http://sandbox.onlinephpfunctions.com/ and http://www.tutorialspoint.com/execute_php_online.php) including my local server and my hosting server. All of these show the some UNIXTIME in sec even if i change the date_default_timezone_set.
Do you have any idea why that is happening?
Upvotes: 0
Views: 3139
Reputation: 166
The function time() returns always timestamp that is timezone independent (=UTC).
Source: http://php.net/manual/pl/function.time.php#100220
Upvotes: 1
Reputation: 171
time()
is timezone independant. This means, it will always return the time in seconds since january 1 1970, no matter how the timezone is configured. It always takes the UTC-time.
Upvotes: 1