【发布时间】:2021-05-17 20:55:08
【问题描述】:
我有问题。在我的代码中,我有以下行:
$RunDateTimeGMT0 = "2017-12-31 23:00:00";
目标是获取上一小时和下一小时,所以我尝试了这个:
$RunDateTimeGMT0 = "2017-12-31 23:00:00";
$epochRunDateTimeGMT0 = strtotime($RunDateTimeGMT0);
$previousEpochDateTimeGMT0 = $epochRunDateTimeGMT0 - 3600;
$nextEpochDateTimeGMT0 = $epochRunDateTimeGMT0 + 3600;
然后我得到以下结果:
previousEpochDateTimeGMT0 -> 2017-12-31 21:00:00
nextEpochDateTimeGMT0 -> 2017-12-31 23:00:00
由于我的时区(+1) RunDateTimeGMT0 被转换为我的时区的日期。
我想要以下结果:
validEpochDateTimeGMT0 -> 2017-12-31 22:00:00
nextEpochDateTimeGMT0 -> 2018-01-01 00:00:00
如何保持日期对象 UTC?
【问题讨论】:
-
您没有展示如何从时间戳到可读日期。而
),在3600之后,一定会报错吗?