【问题标题】:UTC time format to milliseconds in PHP (local timezone issue)PHP 中的 UTC 时间格式到毫秒(本地时区问题)
【发布时间】:2014-11-29 13:28:28
【问题描述】:

我试图从像这样的日期获得毫秒2014-09-15T10:27:29Z

我尝试了以下

return strtotime('2014-09-15T10:27:29Z');

但它返回一个警告:

It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/New_York' for 'EST/-5.0/no DST'

所以,我必须使用函数date_default_timezone_set但不固定为'America/New_York'

$userZone = //I don't know what to put here
date_default_timezone_set($userZone);
return strtotime('2014-09-15T10:27:29Z');

如何获取用户时区?

【问题讨论】:

  • 你想如何得到不存在的东西?

标签: php datetime utc


【解决方案1】:

日期/时间字符串末尾的 Z 表示祖鲁时间,或者更常见的 UTC

UTC 时区有时用字母 Z 表示 - 对等效航海时区 (GMT) 的引用,自 1950 年左右以来一直用 Z 表示。该字母还指“区域描述”为零小时,自 1920 年以来一直使用(参见时区历史)。由于 Z 的 NATO 拼音字母和业余无线电单词是“Zulu”,因此 UTC 有时也称为 Zulu 时间。在航空领域尤其如此,祖鲁语是通用标准。这可确保所有飞行员无论身在何处都使用相同的 24 小时制,从而避免在不同时区之间飞行时出现混乱。

【讨论】:

  • 我知道,但这一次在东京和纽约的显示方式会有所不同。如何显示正确的时间?
  • 如果您使用 DateTime 对象,而不是简单的 unix 时间戳,您可以轻松地显示您想要的任何时区的日期/时间
猜你喜欢
  • 2017-04-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-11-15
  • 1970-01-01
  • 1970-01-01
  • 2015-06-03
相关资源
最近更新 更多