将纪元转换为东部时间,缩短一个小时?

问题描述 投票:0回答:1

我正在尝试将纪元转换为人类友好的日期时间。我还有1小时就下班了为什么?

$aptTime = 1694194200;
if(!empty($aptTime)) {
        $aptDisplay = new dateTime("@$aptTime");
        $aptDisplay->setTimezone(new DateTimeZone('EST'));
        $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>';      
    }

预计产出:9 月 8 日星期五下午 1:30

生成的输出:9 月 8 日星期五中午 12:30

php datetime timezone epoch
1个回答
0
投票

如果您不想确认夏令时

这将为您提供所需的输出

$aptDisplay->setTimezone(new DateTimeZone('Etc/GMT+4'));

或者如果您承认 DST,那么您的解决方案就是准确的。

© www.soinside.com 2019 - 2024. All rights reserved.