将TIMESTAMP和时区转换为其他时区


Convert TIMESTAMP and timezone to a different timezone

所以我在数据库中有一个时间戳,如下所示:2016-03-31 21:10:15这个get在数据库中设置为服务器timezonedate_default_timezone_set("America/Los_Angeles");

现在,当我列出需要将其转换为存储在其他地方的用户时区的数据时,有没有办法将其转换并显示在不同的时区?

因此,如果《美国/洛杉矶》是下午5点,我需要将其转换为纽约,并显示该时间,但对于纽约时区,我想你知道我的意思。

使用DateTime对象,您可以随心所欲地使用时区:

$dateTime = '2016-03-31 21:10:15';
$originalTimezone = 'America/Los_Angeles';
$newTimezone = 'America/New_York';
$dto = new DateTime($dateTime, new DateTimeZone($originalTimezone));
$dto->setTimezone(new DateTimeZone($newTimezone));
echo $dto->format('Y-m-d H:i:s');