将UTC时间戳转换为php中的另一个时间戳



我有一个UTC时区的时间戳。示例:1600532232。现在是标准时间下午4点17分。

我想将这个时间戳转换为另一个带偏移量的时区,然后以常规标准时间输出。

应输出

纽约:下午12:17

洛杉矶:上午9:17

柏林:12:17:下午

北京:11:17:下午

我如何在PHP中做到这一点?

// create a new DateTime with UTC tz
$epoch = 1600532232;
$dt = new DateTime("@$epoch", new DateTimeZone('UTC'));
// change the timezone
$dt->setTimezone(new DateTimeZone('America/New_York'));
// format the date
$dt->format('h:i A');

最新更新