Ok, I'm using an ICS parser utility to parse google calendar ICS files. It works great, except google is feeding me the times of the events at UCT.. so I need to subtract 5 hours now, and 6 hours when daylight savings happens.
To get the start time I'm using:
$timestart = date("g:iA",strtotime(substr($event['DTSTART'], 9, -3)));
//$event['DTSTART'] feeds me back the date in ICS format: 20100406T200000Z
So any suggestions how to handle timezone and daylight savings time?
Thanks in advance
Just don't use the substr() part of the code. strtotime is able to parse the yyyymmddThhiissZ formatted string and interprets the Z as timezone=utc.
e.g.
$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";
prints
Tue, 06 Apr 2010 22:00:00 +0200
Tue, 06 Apr 2010 16:00:00 -0400
edit: or use the DateTime and DateTimezone classes
$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";
(output is the same)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With