I need to display the current time as an epoch in python to pass as a variable into some code how do I go about doing that?
ie. 1458410416
Every method of
import datetime
datetime.datetime()
gives human readable values.
I need to display the current time as an epoch in python to pass as a variable into some code how do I go about doing that?
ie. 1458410416
Every method of
import datetime
datetime.datetime()
gives human readable values.
There is a built-in function in the time
module:
import time
seconds = time.time()
There are many functions in the time
module for seconds since the Epoch, time tuples, etc. I would recommend that you check out the docs.
Import the time
library, and then use this code:
>>> time.mktime(datetime.datetime.now().timetuple())
1458410651.0
time.mktime
converts a datetime
to a Unix epoch timestamp.
epoch_time = int(time.time())
Commented
Mar 19, 2016 at 18:05