如何将 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');
这篇关于UTC 日期/时间字符串到时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!