【发布时间】:2012-01-12 10:53:48
【问题描述】:
我目前正在使用它来将时间戳转换为用户定义的时区。我的问题是 DateTimeZone() 需要像 Europe/Vienna 或 America/Chicago 这样的时区:
$date = new DateTime("@".$timestamp);
$date->setTimezone(new DateTimeZone("America/Chicago"));
我已经在 http://us3.php.net/manual/en/timezones.php 上查看了支持的时区,但是它们太多了,我不希望用户浏览整个列表。
有没有一种简单的方法转换例如GMT+1:00、GMT-4:30 或 GMT+5:45 为 DateTimeZone() 设置正确的值。
或者像我在这里找到的那样使用数组列表更好:Convert selected time and timezone to a set timezone
一般情况下用户选择使用 UTC 还是 GMT 更好?
谢谢!
【问题讨论】:
-
基于 GMT 偏移量的值不明确。给定的偏移量通常映射到多个时区。当跨越夏令时边界时,给定的偏移量可能会变得不适合使用。