【问题标题】:is time() returning same value for all locations (time zones)? [duplicate]time() 是否为所有位置(时区)返回相同的值? [复制]
【发布时间】:2013-08-14 14:47:48
【问题描述】:

Here据说:

时间戳是自格林威治标准时间 1970 年 1 月 1 日午夜以来的秒数。无论您身在何处,给定的时间戳都代表完全相同的时刻,而与时区无关。

所以我尝试了:

$date_str="2010-01-10 12:00";

$TimeZone_toronto=new DateTimeZone('America/Toronto');
$date_obj_toronto=new DateTime($date_str, $TimeZone_toronto);
$date_time_stamp_toronto=$date_obj_toronto->format('U'); 

$TimeZone_GMT=new DateTimeZone('GMT');
$date_obj_GMT=new DateTime($date_str, $TimeZone_GMT);
$date_time_stamp_GMT=$date_obj_GMT->format('U');

根据上面的报价:应该是 $date_time_stamp_toronto==$date_time_stamp_GMT

但这里是值:

$date_time_stamp_toronto = 1263142800
$date_time_stamp_GMT     = 1263124800

所以 => $date_time_stamp_toronto!=$date_time_stamp_GMT 因为:

1263142800!=1263124800

真相在哪里?

【问题讨论】:

  • 事实上它运行良好 3v4l.org/Ms108 。另外,不要使用 GMT,而是使用 UTC uk1.php.net/manual/en/timezones.others.php 查看页面中间的红色框。
  • 您错过了多伦多的2010-01-10 12:002010-01-10 12:00 GMT 确实指的是同一时间。
  • vascowhite:如果 $date_str="now";.. 我会得到与你在 demi 中显示的时间戳相同的时间戳;但是 $date_str="2010-01-10 12:00";
  • 为什么你会认为多伦多的 12:00 = 格林威治标准时间 12:00?显然不是。 3v4l.org/9T7sJ 有帮助吗?

标签: php


【解决方案1】:

“2010-01-10 12:00”分别是多伦多和格林威治当地时间具有不同时间戳的两个非常不同的时间。

【讨论】:

  • 如果2010-01-10 12:00 本地时间 根据时区不同,为什么now 不是(假设也是本地时间)? DEMO.
  • 因为 now 是在那个位置 now 的任何时间。那个位置的 12 点不是现在,而是世界不同地区不同时间的 12 点。您是否期望“现在”意味着“采用现在 在我的时区中的任何挂钟时间,并使用与不同时区中的挂钟时间相同的数字”?这是没有意义的。 :)
  • 但是now 在指定时区时肯定应该指的是那个时区中的now,对吧?
  • 2010-01-19 12:00 在多伦多是 2010-01-19 16:00 GMT
  • @deceze 哇哦 - 我一定是半睡半醒 - 是时候回家了,因为我的大脑显然已经完成了今天的工作。感谢 ELI5 的解释。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-11-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多