I have a Python datetime object that I want to convert to unix time, or seconds/milliseconds since the 1970 epoch.
datetime
How do I do this?
This is how I do it:
from datetime import datetime from time import mktime dt = datetime.now() sec_since_epoch = mktime(dt.timetuple()) + dt.microsecond/1000000.0 millis_since_epoch = sec_since_epoch * 1000