好了,我正在使用ICS解析器实用程序来解析google日历ICS文件。它工作得很好,除了google给我提供了UCT事件的时间。所以我现在需要减去5个小时,当夏令时发生时是6个小时。
要获取我正在使用的开始时间:
$timestart = date("g:iA",strtotime(substr($event['DTSTART'], 9, -3)));
//$event['DTSTART'] feeds me back the date in ICS format: 20100406T200000Z那么有什么建议如何处理时区和夏令时呢?
提前感谢
发布于 2010-04-09 23:28:08
只是不要使用代码中的substr()部分。timezone=utc能够解析yyyymmddThhiissZ格式的字符串,并将Z解释为strtotime。
例如:
$event = array('DTSTART'=>'20100406T200000Z');
$ts = strtotime($event['DTSTART']);
date_default_timezone_set('Europe/Berlin');
echo date(DateTime::RFC1123, $ts), "\n";
date_default_timezone_set('America/New_York');
echo date(DateTime::RFC1123, $ts), "\n";打印
Tue, 06 Apr 2010 22:00:00 +0200
Tue, 06 Apr 2010 16:00:00 -0400编辑:或使用DateTime和DateTimezone类
$event = array('DTSTART'=>'20100406T200000Z');
$dt = new DateTime($event['DTSTART']);
$dt->setTimeZone( new DateTimezone('Europe/Berlin') );
echo $dt->format(DateTime::RFC1123), "\n";
$dt->setTimeZone( new DateTimezone('America/New_York') );
echo $dt->format(DateTime::RFC1123), "\n";(输出相同)
发布于 2010-04-09 23:32:27
如果您已经设置了时区区域设置,那么您还可以使用date("T"),它将返回当前时区。
echo date("T");因为我们在夏令时,(在我的时区)它返回: EDT
然后,您可以在IF语句中使用它来调整时区调整。
if (date("T") == 'EDT')
$adjust = 6;
else
$adjust = 5;https://stackoverflow.com/questions/2608558
复制相似问题