For Developers

Unix Timestamp in Python

How to get the current timestamp, convert it to a date, and convert a date back to a timestamp in Python — plus the specific mistake that trips up Python code more than any other.

import time
time.time()
import datetime
datetime.datetime.fromtimestamp(1750000000, datetime.timezone.utc)
import datetime
datetime.datetime(2025,6,15,12,0,0, tzinfo=datetime.timezone.utc).timestamp()

The Python-specific pitfall

Python's real trap isn't the unit — it's naive vs. aware datetimes. datetime.now() returns a naive datetime with no timezone attached at all, and Python won't warn you when you compare or subtract it against an aware one; the result is either a crash or, worse, a silently wrong duration. Always construct datetimes as timezone-aware from the start — see How to Handle Timezones Correctly in Python for the full pattern.

Have a timestamp right now?

Paste it into the Timestamp ⇄ Date Converter to check it instantly, in any timezone, without writing any code. Working across several languages on the same project? The full Epoch Time in Programming Languages guide has all of them side by side for quick comparison.

Related

Related tools & reading