DateTime-> format("U")不返回带有时区信息的值

Moo*_*oon 0 php timezone datetime

在PHP 5.2中,我使用以下代码从DateTime对象获取时间戳.

$dateTime = new DateTime("now", new DateTimeZone("America/Los_Angeles") );

echo $dateTime->format("U");
Run Code Online (Sandbox Code Playgroud)

问题是format("U")只返回服务器时间戳,即UTC.

如何让它返回太平洋时区(洛杉矶)的时间戳?

xda*_*azz 6

您的时间戳概念不正确,时间戳与时区无关,它定义为自1970年1月1日午夜协调世界时(UTC)以来经过的秒数.