【发布时间】:2011-04-08 16:52:15
【问题描述】:
我想将 php 中的日期从 UTC 格式转换为 UTC+5。 如果是从 GMT 到 GMT+5,我会这样做:
$date_str = '2011-04-01 12:00:00'; //ex:from database
$date = new DateTime($date_str,new DateTimeZone('GMT'));
$date->setTimezone(new DateTimeZone('Etc/GMT+5'));
echo $date->format('Y-m-d H:i:s'); //testing
在 php 时区列表 here 中,没有等效的 'Etc/UTC+5'。
有没有办法在 php 中将 UTC 转换为 UTC+5?
还是会产生与 GMT 示例相同的结果?
将“UTC”转换为“Etc/GMT+5”会不会出错?
注意事项:
- 我实际使用的日期(来自我的数据库)是 UTC 格式。
- 对于 UTC 和 GMT 时间格式之间的差异,我仍然有些困惑。
【问题讨论】: