You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

将Epoch时间转换为EST时区时偏差1小时,原因何在?

问题:Epoch时间转EST时区偏差1小时的原因及解决办法

你在PHP中将Epoch时间1694194200转换为可读日期时间时,结果比预期慢了1小时:

  • 预期输出:Friday September 8th at 1:30 PM
  • 实际输出:Friday September 8th at 12:30 PM

原因分析

问题出在你使用的EST时区上:

  • EST是北美东部标准时间,固定为UTC-5,不考虑夏令时;
  • 而你转换的时间点(2023年9月8日)属于北美东部的夏令时时段,此时当地实际使用的是EDT(北美东部夏令时,UTC-4),直接用EST会导致时间少算1小时。

解决办法

改用America/New_York时区,这个时区会自动识别夏令时与标准时间的切换,无需手动调整:

$aptTime = 1694194200;
if(!empty($aptTime)) {
        $aptDisplay = new DateTime("@$aptTime");
        // 使用自动适配夏令时的时区
        $aptDisplay->setTimezone(new DateTimeZone('America/New_York'));
        $aptStr = date_format($aptDisplay, "l F jS \a\t g:i A");
        $html = '<p class="feature-box-desc text-dark" id="apt"><strong>' . $aptStr . '</strong></p>';      
    }

修改后,转换结果会自动匹配夏令时,得到你预期的Friday September 8th at 1:30 PM。

内容的提问来源于stack exchange,提问作者DDulla

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.11 10:55:27