Converting datetime to POSIX time
For UTC calculations, calendar.timegm
is the inverse of time.gmtime
.
import calendar, datetime
d = datetime.datetime.utcnow()
print calendar.timegm(d.timetuple())
import time, datetime
d = datetime.datetime.now()
print time.mktime(d.timetuple())