Facebook Events and time zones, how to convert UTC datetime to what facebook expects?

My application should create facebook events. Everything is working fine, but I cannot correctly determine the timestamps. Start and end dates are not true. Facebook event API docs report the following:

Note: start_time and end_time are the times that the event creator entered, converted to UTC, assuming they are in Pacific time (summer savings or standard, depending on the date of the event), and then converted to Unix era time.

(a source)

I can’t understand what this means.

My web application is a python (django) site. Given a datetime object that has a start / end time in UTC, what is the magic spell for pytz calls to get the right time to post to facebook?

+2
source share
2 answers

" Unix epoch time " simply means "the number of seconds since January 1, 1970 (not counting the seconds of the jump)."

By the way, this description of the Facebook event API is so strange, I cannot believe that it is correct as described. They seem to be asking:

  • The time that was created by the creator of the event;
  • It is interpreted as local time in the Pacific time zone with the current daylight saving time rules for this zone;
  • Converted to UTC.

I live in the UTC + 0 time zone. Therefore, if I plan an event on 2010-11-09 12:00:00 UTC, the time that is actually posted to Facebook (Unix time corresponds) 2010-11-09 20:00: 00 UTC. How is that right? Perhaps I misunderstood.

+1
source

This means that if the user enters "12 a.m.", you must accept his "12 am am Pacific time", convert it to UTC so that his "8 a.m. GMT" and turn it into a unix era.

You can do it as follows:

 import datetime, calendar date_local = datetime.datetime.now() # some date in some timezone date_utc = date_local.utctimetuple() unix_time = calendar.timegm(date_utc) # to unix time 
+2
source

All Articles