How to get current time in seconds in Python
In this tutorial, we will discuss how to get the current time in seconds in Python.
In Python, there are many ways to get the current time. One such way is Time module. Time module has various functions to get the current time.
Some of the time module functions are:
Get current time in seconds in Python
time.time() function gives current time in seconds since the epoch as a floating number.
Let’s see the code
# import the time module import time # get current time in seconds t = time.time() print('Time:', t) # get current time in seconds as integer s = int(round(time.time())) print('Rounded Time:', s)
Time: 1643189517.22833 Rounded Time: 1643189517
In the above output, there are two outputs which are exact time in the format of seconds.mircroseconds and the other in the format of seconds which is rounded as integer.