date_default_timezone_set(); NOT working

青春壹個敷衍的年華 提交于 2019-12-12 03:35:15

问题


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?


回答1:


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.




回答2:


The function time() returns always timestamp that is timezone independent (=UTC).

Source: http://php.net/manual/pl/function.time.php#100220



来源:https://stackoverflow.com/questions/36390778/date-default-timezone-set-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!