简体   繁体   中英

python - how to display time as epoch?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM