Skip to content

Instantly share code, notes, and snippets.

@lukem
Created October 5, 2017 22:30
Show Gist options
  • Save lukem/5599ffc63216e069434bc363be22712d to your computer and use it in GitHub Desktop.
Save lukem/5599ffc63216e069434bc363be22712d to your computer and use it in GitHub Desktop.
Parse ISO-8601 dates into UTC seconds since epoch
import calendar
import dateutil.parser
import time
def parseIso8601(timestr):
"""Parse `timestr` into UTC seconds since epoch."""
dt = dateutil.parser.parse(timestr)
if dt.tzinfo:
return calendar.timegm(dt.utctimetuple())
else:
return time.mktime(dt.timetuple())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment