如何将 UTC 日期时间转换为另一个时区?

2022-01-16 00:00:00 datetime timezone php

如何将这样的日期转换为:2012-07-16 01:00:00 +00(它位于 UTC +00:00 时区)UTC +04:00 时区?确保正确处理夏令时?

How can i convert a date like this: 2012-07-16 01:00:00 +00 (it's in the UTC +00:00 timezone) to UTC +04:00 timezone? Ensuring that daylight saving will be handelled correctly?

推荐答案

使用DateTimeDateTimeZone.

$date = new DateTime('2012-07-16 01:00:00 +00');
$date->setTimezone(new DateTimeZone('Europe/Moscow')); // +04

echo $date->format('Y-m-d H:i:s'); // 2012-07-15 05:00:00 

相关文章