Frage

I insert an event with Google Calendar API for Python client and somehow the time there is 1 hour later than intended.

Here's the snippet. Imports:

import gdata.calendar.data
import gdata.calendar.client
import gdata.acl.data
import atom.data

Connect to the Google Calendar:

calendar_client = gdata.calendar.client.CalendarClient(source='noApp')
calendar_client.ClientLogin('account@gmail.com', 'password', calendar_client.source)

Create event:

event = gdata.calendar.data.CalendarEventEntry()
date='2012-10-29T18:30:00.001Z' # This is the time of event that I want to insert
event.when.append(gdata.calendar.data.When(start=date))

And finally, insert the event

new_event = calendar_client.InsertEvent(event)

As a result I have in the calendar the time 19:30 on 29-th of October, and not 18:30.
I tried to change the time zone to '000Z' instead of '001Z' in the date variable, but it didn't help. Of course, I can subtract an hour in advance, but why does it happen?

War es hilfreich?

Lösung

18:30:00.000Z and 18:30:00.001Z are given in the same timezone, namely Z for UTC, but separated by one millisecond -- since the 0 you changed to 1 was in the fractional seconds part of the timestamp.

If you want to give the API times in CET rather than UTC, you could try something like 2012-10-29T18:30:00+01:00 (if the API supports RFC-3339 timestamps). Or, if that doesn't work, convert your desired time to UTC first.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top