Python Current Unix Timestamp

Python Current Unix Timestamp

In Python, to get UNIX timestamp, you need to use the time library like below.

import time
time.time()
#1602044323.063782
#int(time.time())

Since its type is a float, you need to cast to int if you need.

Furthermore, if you want to consider your timezone, you can simply add the hours like below. The following example is the utc+9 case.

import time
timezone = 60*60*9 # seconds * minutes * utc + 9
utc_timestamp = int(time.time() + timezone)
print(utc_timestamp)

Happy coding!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: