Created
October 5, 2017 22:30
-
-
Save lukem/5599ffc63216e069434bc363be22712d to your computer and use it in GitHub Desktop.
Parse ISO-8601 dates into UTC seconds since epoch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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