简体   繁体   English

date_default_timezone_set(); 无法运作

[英]date_default_timezone_set(); NOT working

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. 在几个站点( http://sandbox.onlinephpfunctions.com/http://www.tutorialspoint.com/execute_php_online.php )中,包括我的本地服务器和托管服务器。 All of these show the some UNIXTIME in sec even if i change the date_default_timezone_set. 即使我更改了date_default_timezone_set,所有这些都以秒为单位显示了一些UNIXTIME。

Do you have any idea why that is happening? 您知道为什么会这样吗?

time() is timezone independant. time()与时区无关。 This means, it will always return the time in seconds since january 1 1970, no matter how the timezone is configured. 这意味着,无论时区如何配置,它将始终以秒为单位返回自1970年1月1日以来的时间。 It always takes the UTC-time. 它总是需要UTC时间。

The function time() returns always timestamp that is timezone independent (=UTC). 函数time()始终返回与时区无关的时间戳(= UTC)。

Source: http://php.net/manual/pl/function.time.php#100220 资料来源: http : //php.net/manual/pl/function.time.php#100220

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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