Skip to content

Instantly share code, notes, and snippets.

@pythonjunkie
pythonjunkie / iso8601_to_epoch.py
Created August 29, 2012 18:19
Convert given time in ISO8601 and converts it to epoch time
import datetime, time
def convert_enddate_to_seconds(self, ts):
"""Takes ISO 8601 format(string) and converts into epoch time."""
dt = datetime.datetime.strptime(ts[:-7],'%Y-%m-%dT%H:%M:%S.%f')+\
datetime.timedelta(hours=int(ts[-5:-3]),
minutes=int(ts[-2:]))*int(ts[-6:-5]+'1')
seconds = time.mktime(dt.timetuple()) + dt.microsecond/1000000.0
return seconds