【问题标题】:PHP strtotime timezonePHP strtotime 时区
【发布时间】:2016-04-22 12:12:57
【问题描述】:

我在将 PHP strtotime 转换为不同时区时遇到问题。 我的代码很简单:

<?php
date_default_timezone_set("Europe/Bratislava");
echo date("H:i",strtotime("20:00 America/New_York")); 
?>

此代码正在返回:02:00。 但它应该返回 14:00。

你能帮我解决这个问题吗?

【问题讨论】:

  • 如果在日期后面加上“Y m d”会发生什么?也许它读作 20:00 是别的东西

标签: php timezone strtotime


【解决方案1】:

此代码返回:02:00。但它应该返回 14:00。

不,没错。您正在从纽约晚上 8 点(由于 DST,目前为 UTC-4)转换为欧洲/布拉迪斯拉发时区(由于 DST,目前为 UTC+2)。

所以:

New York:   8pm
UTC:        Midnight
Bratislava: 2am

如果您尝试将欧洲/布拉迪斯拉发时间转换为纽约时间,则需要切换时区 ID。

【讨论】:

  • 纽约是UTC-5,布拉迪斯拉发是UTC+1
  • @MateiMihai:夏天不会。 DST 每增加一个小时。
  • 谢谢你的回答,我想从布拉迪斯拉发换到纽约,请问怎么做?
  • @RomanHolic:正如我在答案中所说,切换您的时区 ID。
猜你喜欢
  • 2011-04-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-07-12
  • 2020-11-21
  • 2011-12-25
  • 2012-09-13
相关资源
最近更新 更多