UTC日期/时间字符串到时区 [英] UTC Date/Time String to Timezone

查看:201
本文介绍了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');

这篇关于UTC日期/时间字符串到时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆