In Python, how to get the epoch time (the number of seconds since epoch)?

In Python, you can get the epoch time by calling time.time() which return a floating number:

import time

print time.time()

If you would like to get only the number of seconds, you may convert it to an integer.

One example is as follows.

$ python3
Python 3.8.5 (default, Jul 28 2020, 12:59:40) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import time
>>> t = time.time()
>>> print(t)
1603532174.7085965
>>> print(int(t))
1603532174

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *