import time
timestamp = time.time()
print(timestamp)
Output
1643920477.7901955
We are using the time module here to get the current timestamp. We are importing the time module using the import keyword.
import time
Then we are using the time() function of the time module to get the current timestamp.
We can also use the Python datetime module to get the current timestamp in Python. All you need to do is import the datetime module in your Python code and use its datetime() function.
Code Example
import datetime;
current_timestamp = datetime.datetime.now().timestamp()
print(current_timestamp)
Output
1643995600.095005
If you do not want to use the float value of the timestamp, you can convert it to int using the Python int() function and pass the timestamp value to it.
print(int(current_timestamp))
Output
1643995909
0 Comments