俄亥俄州哥伦布市位于 EDT 时区,但 PHP::DateTime 使用这些 php 时区 我似乎找不到一个给我正确时间的。美国/纽约晚了一个小时,因为在美国东部夏令时间结束之前我们是+5而不是4。
我很困惑。例如,现在大概是上午 11:26,我是上午 10:26 回来的。服务器设置了正确的时间,我尝试使用 date_default_timezone_set("EDT") 但这是不允许的。
$fromZone = 'Europe/London';
$toZone = 'American/New_York';
function adjustTime($time, $fromZone, $toZone){
$date = new DateTime($time, new DateTimeZone($fromZone));
$date->setTimezone(new DateTimeZone($toZone));
return $date->format('Y-m-d H:i:s');
}
例如:我从肥皂网络服务“2010-09-23 15:25:56”收到,这是欧洲/伦敦时间,它应该转换为“2010-09-23 11:25:56”,这是 EDT 时间。我试图使用上面的函数,这返回“2010-09-23 10:25:56”
Columbus, Ohio is in EDT timezone but PHP::DateTime uses these php timezones and I cannot seem to find one that gives me correct time. America/New_York is off by an hour because until EDT ends we are +5 not 4.
I am confused. For example right now its 11:26AM roughly speaking and I get back 10:26AM. The server has the right time set on it, I tried using date_default_timezone_set("EDT") but this is not allowed.
$fromZone = 'Europe/London';
$toZone = 'American/New_York';
function adjustTime($time, $fromZone, $toZone){
$date = new DateTime($time, new DateTimeZone($fromZone));
$date->setTimezone(new DateTimeZone($toZone));
return $date->format('Y-m-d H:i:s');
}
For example: I receive from a soap web service "2010-09-23 15:25:56" which is Europe/London time and it should be transformed to "2010-09-23 11:25:56" which is EDT time. I was trying to use the function above and this is returning back "2010-09-23 10:25:56"
发布评论
评论(1)
鉴于在撰写本文时,“America/New_York”应该为您提供正确的值 纽约也是 11.36。请注意,这是 UTC-4(当前为 UTC 15:35)。在标准时间中,您是 UTC-5。
EDT 并不是真正的“完整”时区 - 它只是其中的白天部分。像“America/New_York”这样的时区名称提供了完整时区实现。
现在至于为什么你的服务器给出了错误的值,那是另一回事......如果你询问 UTC 时间,它会给你什么?
编辑:正如评论中提到的,修复方法是从 UTC 转换,而不是从欧洲/伦敦转换:(
可能有更好的方法;我不是 PHP 开发人员。)
"America/New_York" should give you the right value, given that at the time of this writing it's 11.36 in New York too. Note that that's UTC-4 (it's currently 15:35 UTC). In standard time, you're UTC-5.
EDT isn't really a "full" time zone - it's just the daylight part of it. A time zone name like "America/New_York" gives the complete time zone implementation.
Now as to why your server is giving the wrong value, that's a different matter... if you ask for the UTC time, what does it give you?
EDIT: As mentioned in the comments, the fix is to convert from UTC, not from Europe/London:
(There may be a better way of doing it; I'm not a PHP developer.)