Convert Unix timestamps in Python with live parser and datetime/timezone snippets. UTC-aware patterns included.
Smart Universal Parser
// Paste Unix seconds/ms, ISO 8601, RFC 2822, or a human date.
Developer Snippets
// Copy-ready code — current timestamp injected automatically.
Python gives you two layers for time: the low-level time module, which returns raw epoch numbers, and the datetime module, which builds calendar objects. The safe modern pattern is simple: get epoch seconds, convert them to a timezone-aware datetime in UTC, and change zones only when displaying. Use the live parser above to check any value, then copy the Python snippet it generates. Parsing happens in your browser; pasted timestamps are never uploaded.
time.time() and friendstime.time() returns seconds since the epoch as a float with sub-second precision. Wrap it in int() for whole Unix seconds. time.time_ns() returns an integer number of nanoseconds, which avoids float rounding when you need milliseconds:
import time
seconds = int(time.time()) # e.g. 1715429912
millis = time.time_ns() // 1_000_000 # integer millisecondsfromtimestamp (timezone-aware)Always pass tz=timezone.utc. Without it, datetime.fromtimestamp() returns a naive datetime in the server’s local timezone, so the same code prints different results on your laptop and in production.
from datetime import datetime, timezone
from zoneinfo import ZoneInfo
dt = datetime.fromtimestamp(1715429912, tz=timezone.utc)
print(dt.isoformat()) # 2024-05-11T12:18:32+00:00
print(dt.astimezone(ZoneInfo("Asia/Tokyo"))) # 2024-05-11 21:18:32+09:00
print(int(dt.timestamp())) # 1715429912That confirms 1715429912 is Saturday, May 11, 2024 at 12:18:32 UTC. For milliseconds, divide first: datetime.fromtimestamp(ms / 1000, tz=timezone.utc).
utcfromtimestamp() is deprecateddatetime.utcfromtimestamp() and datetime.utcnow() are deprecated since Python 3.12. They return naive datetimes that hold UTC values but carry no timezone, so later calls like .timestamp() treat them as local time and shift the result by your offset. Replace them with datetime.fromtimestamp(ts, tz=timezone.utc) and datetime.now(timezone.utc). (datetime.UTC is an alias for timezone.utc on Python 3.11+.)
zoneinfoSince Python 3.9, the standard library includes zoneinfo, which reads the IANA timezone database. It replaces most uses of pytz and handles daylight saving time correctly when you call astimezone(). On Windows or slim containers without system tz data, install the tzdata package from PyPI.
from datetime import datetime, timezone
aware = datetime(2024, 5, 11, 12, 18, 32, tzinfo=timezone.utc)
int(aware.timestamp()) # 1715429912
int(datetime.fromisoformat("2024-05-11T12:18:32Z").timestamp()) # 1715429912 (3.11+)Calling .timestamp() on a naive datetime assumes local time, a quiet source of off-by-hours bugs. Keep datetimes aware from creation to storage. The full walkthrough, including pandas and string formatting, is in Convert a timestamp to a date in Python. If your data lives in Postgres, compare with the PostgreSQL timestamp guide.
In data work, epoch columns usually arrive as integers. pd.to_datetime(df["ts"], unit="s", utc=True) converts a whole column to timezone-aware UTC timestamps in one vectorized call. Use unit="ms" for JavaScript-style milliseconds. Passing utc=True matters for the same reason tz=timezone.utc does in plain Python: naive values end up interpreted inconsistently later. Convert to a display zone at the end with .dt.tz_convert("Europe/Paris").
TypeError. Standardize on aware UTC.fromtimestamp raises ValueError: year is out of range or lands tens of thousands of years in the future. Divide by 1000.time.time() is a float; use time_ns() when exact milliseconds matter.fromisoformat and “Z”. Parsing a trailing Z needs Python 3.11 or later. On older versions, replace Z with +00:00.Use int(time.time()) for seconds, or time.time_ns() // 1_000_000 for integer milliseconds.
Call datetime.fromtimestamp(ts, tz=timezone.utc). For 1715429912 this returns 2024-05-11 12:18:32+00:00.
Yes, since Python 3.12, together with utcnow(). Both return naive datetimes. Use datetime.fromtimestamp(ts, tz=timezone.utc) and datetime.now(timezone.utc) instead.
For Python 3.9+, use the standard-library zoneinfo with IANA names such as ZoneInfo('Europe/Paris'). Install tzdata if the system has no timezone database.
The datetime is probably naive, so Python treats it as local time. Attach tzinfo=timezone.utc, or build it with an aware constructor, before calling .timestamp().
Yes. The converter on this page runs in your browser and never sends pasted values to a server.