Get Current Timestamp in Python
Getting the current Unix timestamp in Python is straightforward with the time module. The time.time() function returns a float representing the current time as seconds since the Unix epoch. Convert it to an integer to get a standard 10-digit Unix timestamp, or multiply by 1000 and convert to get a 13-digit millisecond timestamp.
Python offers several ways to get the current timestamp, each with slightly different characteristics. The time.time() approach is the most common and most portable. The datetime module approach gives you more flexibility for formatting. The time.time_ns() approach (Python 3.7+) gives you nanosecond precision without floating-point rounding errors.
All methods to get the current timestamp in Python
Simplest — seconds as float:
import time
time.time() # e.g. 1700000000.123456
As integer (10-digit Unix):
int(time.time()) # e.g. 1700000000
As milliseconds (13-digit):
int(time.time() * 1000)
As nanoseconds (no float errors, Python 3.7+):
time.time_ns() # returns int in nanoseconds
Using datetime (UTC-aware):
from datetime import datetime, timezone
int(datetime.now(timezone.utc).timestamp())
Formatted current timestamp:
datetime.now(timezone.utc).strftime('%Y-%m-%d %H:%M:%S UTC')
The live timestamp at the top of this page shows the current Unix time — compare it to your Python output as a quick sanity check.