UTC 日期/时间字符串到时区
如何将 UTC 的日期/时间字符串(例如 2011-01-01 15:00:00)转换为 php 支持的任何给定时区,例如 America/New_York 或 Europe/San_Marino.
How do I convert a date/time string (e.g. 2011-01-01 15:00:00) that is UTC to any given timezone php supports, such as America/New_York, or Europe/San_Marino.
推荐答案
PHP的DateTime
对象非常灵活.
PHP's DateTime
object is pretty flexible.
$UTC = new DateTimeZone("UTC");
$newTZ = new DateTimeZone("America/New_York");
$date = new DateTime( "2011-01-01 15:00:00", $UTC );
$date->setTimezone( $newTZ );
echo $date->format('Y-m-d H:i:s');
相关文章