Working with time in Python is confusing. There are three different standard types for representing time: seconds since epoch, tuples, and the datetime module. And there's common add-ons like mxDateTime and database times.
I was having a heck of a time parsing RFC 822 strings like you see in HTTP headers and email. The problem is timezones are not supported by strptime() or the tuple format. But the Web is my programmer:
def parseRFC822Time(t): return calendar.timegm( time.strptime(t, "%a, %d %b %Y %H:%M:%S %Z"))The magic here is the calendar module which has the timegm() function missing from the time module.
Thanks to a couple of readers for pointing out there's also a rfc822.parsedate() function.