Importing ICS into Google Calendar with correct timezone

sesquiped picture sesquiped · May 30, 2014 · Viewed 13.6k times · Source

I'm trying to import a simple ics file into Google calendar. However, even though I have the timezone specified, Google calendar still imports the wrong event time. (Although it does say that the wrong time is in the correct timezone.)

Here is a sample of my ics file:

BEGIN:VCALENDAR
BEGIN:VEVENT
DESCRIPTION: Test_Description
DTEND;TZID=US-Pacific:20140606T180000
DTSTART;TZID=US-Pacific:20140606T170000
LOCATION:Test_Location
SUMMARY:Test_Summary
UID:20140606T150000@NL
END:VEVENT
END:VCALENDAR

This event should show up as occurring on June 6, from 5PM-6PM Pacific Standard Time. However, on my calendar it shows up as occurring on June 6, from 10AM-11AM PST.

I think (although have not implemented) a hack to just change everything to UTC and adjust the event time accordingly might work. However, this would be a little annoying to implement and honestly Google Calendar should be able to handle this simple of an import.

Does anyone have any suggestions to deal with this, or see any bugs in my ICS file?

Thanks!

Answer

chris picture chris · Jan 7, 2016

To make your ICS work with Google's "Add by URL..." specify your timestamps in UTC and add the X-WR-TIMEZONE. Timestamp must have the Z at the end to mark the timestamp as UTC:

DTSTART:20140102T110000Z

Also add the timezone specification in the VCALENDAR block like this:

X-WR-TIMEZONE:Europe/Zurich

After adding the calendar in Google Calendar, the time zone for should be set correctly in the calendar's settings.

If you are using PHP to generate the ICS, you can convert the timestamps to UTC like this:

// The timestamp in your local time and your local time zone
$timestamp = "01.01.2016 12:00";
$timezone = new DateTimeZone('Europe/Zurich');

// The UTC timezone
$utc = new DateTimeZone('UTC');

// Create a DateTime object from your timestamp using your local timezone
$datetime = DateTime::createFromFormat("d.m.Y H:i",$timestamp, $timezone);

// Set the timezone on the object to UTC.
$datetime->setTimezone($utc);

// Print the time in UTC and use the correct format for ICS
echo $datetime->format('Ymd\THis\Z');

This also works on Apple's iPhones.