【发布时间】:2017-02-04 17:57:34
【问题描述】:
我正在尝试获取一个本地时间,给定一个 ISO 8601 格式的祖鲁时间日期时间字符串和一个时区字符串。我阅读了有关 DateTime 对象和 DateTimeZone 的 PHP 文档,并且尝试了很多东西,但我似乎无法获得正确的本地时间。我现在拥有的:
$datetime = '2017-05-29T10:30:00Z'; // I'm getting this value from an API call
$timezone = 'Europe/Prague'; // I'm getting this value from an API call
$date = new \DateTime( $datetime, new \DateTimeZone( $timezone ) );
var_dump( $date->format('H:i') );
// I would expect it to be 12:30 since 29th May for this timezone would be GMT+2, but I get 10:30
所以很明显,我错过了有关 DateTime 和 DateTimeZone 类的一些内容,但我无法正确理解。有人能帮我吗?
【问题讨论】:
标签: php date datetime time iso8601