Code snippets / Python
Convert a Unix timestamp to a date in Python
Python keeps two time APIs: `time` for raw floats and `datetime` for objects. `time.time()` returns a float in seconds; `int()` truncates it to the classic epoch value.
`datetime.fromtimestamp(ts, tz=timezone.utc)` converts a timestamp into a timezone-aware object you can format or serialize with `.isoformat()`.
Current Unix timestamp (seconds)
import time
now_ts = int(time.time())
print(now_ts) # 1,754,136,000 Convert epoch seconds → human-readable UTC
from datetime import datetime, timezone
dt = datetime.fromtimestamp(1754136000, tz=timezone.utc)
print(dt.isoformat()) # 2025-08-02T12:00:00+00:00 Convert ISO 8601 → epoch seconds
from datetime import datetime
secs = int(datetime.fromisoformat("2025-08-02T12:00:00+00:00").timestamp())
print(secs) # 1754136000 Example values used above: epoch seconds = 1,754,136,000 · ISO 8601 = 2025-08-02T12:00:00.000Z
Need more languages? Browse all the Unix timestamp code snippets. Curious how the numbers work? See the Unix epoch time FAQ, or view the current epoch time in any timezone.
Epoch → Human Date
Try it live — convert any timestamp in Python-friendly format.
Seconds or milliseconds — the unit is auto-detected. Example: 1735689600
UTC ISO 8601
–
Local — auto
–
RFC 2822 / GMT
–
Seconds value
–
Relative time
–