import datetime as dt
import time
now=dt.datetime.now()
The era is defined as 1970-01-01 00:00:00 GMT. You can find the number of seconds between nowand Epoch as follows:
print(time.mktime(now.timetuple()))
# 1289565310.0
Or, if you want to find the number of seconds between two dt.datetime objects:
now2=dt.datetime(2010,11,12,12,0,0)
def timestamp(date):
return time.mktime(date.timetuple())
print(timestamp(now2)-timestamp(now))
source
share