Get Current Timestamp in Python

Current Unix Time
Advertisement

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.

Advertisement
// Epoch → Human-readable date

Auto-detects seconds (10 digits), milliseconds (13), microseconds (16), nanoseconds (19)

Invalid timestamp. Please enter a numeric Unix timestamp.
// Date → Epoch timestamp
Please check the values — year (1970–9999), month (1–12), day (1–31), hour (0–23), min/sec (0–59).

Or paste a date string:

Could not parse that date string.
Advertisement

← Back to all tools

Copied!