Dealing With Dates
Simon Willison: Django vs feedparser on dates. Some useful tips in the comments. I find Python’s timezone stuff endlessly frustrating: I know it can do what I want, but it always takes me a ridiculously long time to figure out the necessary incantations.
My recommendation is to convert to UTC as early as possible, stay in UTC as long as possible, and convert to local time as late as possible — preferably in JavaScript on the client.
>>> import datetime,calendar >>> feedparser_timestamp=(2004, 11, 19, 5, 13, 31, 4, 324, 0) >>> datetime.datetime.utcfromtimestamp(calendar.timegm(feedparser_timestamp)) datetime.datetime(2004, 11, 19, 5, 13, 31)