Timeplain
Unix Timestamp to Python datetime Converter
Convert Unix timestamps to Python datetime values. Generate timezone-aware Python examples with UTC, zoneinfo, and expected output.
Convert a Unix timestamp to a Python datetime
Enter Unix seconds or milliseconds below, choose a destination timezone, and select Convert. Open “Show Python code for your converted time” for an example using that instant. This fixed example converts 1700000000 Unix seconds to UTC and America/New_York.
# Python 3.9+; install tzdata if system timezone data is unavailable.
from datetime import datetime, timedelta, timezone
from zoneinfo import ZoneInfo
# Integer milliseconds preserve precision, including before 1970.
timestamp_ms = 1700000000000
date = datetime(1970, 1, 1, tzinfo=timezone.utc) + timedelta(milliseconds=timestamp_ms)
local = date.astimezone(ZoneInfo("America/New_York"))
print(date.isoformat(timespec="milliseconds").replace("+00:00", "Z"))
print(local.isoformat(timespec="milliseconds"))Expected output
2023-11-14T22:13:20.000Z
2023-11-14T17:13:20.000-05:00Result
- Timezone
- —
- Offset
- —
Earlier occurrence
—
- Timezone
- —
- Offset
- —
- Unix timestamp
- —
Later occurrence
—
- Timezone
- —
- Offset
- —
- Unix timestamp
- —
Other formats
Convert a time to see its formats.
- Unix seconds
—- Unix milliseconds
—- ISO 8601 — UTC
—- ISO 8601 — destination timezone
—- RFC 3339 — UTC
—- HTTP date — GMT
—
Earlier occurrence
- Unix seconds
—- Unix milliseconds
—- ISO 8601 — UTC
—- ISO 8601 — destination timezone
—- RFC 3339 — UTC
—- HTTP date — GMT
—
Later occurrence
- Unix seconds
—- Unix milliseconds
—- ISO 8601 — UTC
—- ISO 8601 — destination timezone
—- RFC 3339 — UTC
—- HTTP date — GMT
—
ISO 8601 and RFC 3339 UTC values match for ordinary dates. HTTP dates use whole seconds. RFC 3339 and HTTP dates require a four-digit year.
Show Python code for your converted time
Your converted time in Python
Generate timezone-aware Python datetime code for the resolved instant using UTC and zoneinfo.
Convert a time to generate an example.
Expected output
Earlier occurrence
Expected output
Later occurrence
Expected output
Requires Python 3.9+ and timezone data (install tzdata if needed). Supports years 1–9999. Repeated local times produce two examples. Generated code reproduces resolved instants; it does not validate arbitrary local-time input.
Convert a datetime back to Unix seconds
from datetime import datetime, timezone
value = datetime(2023, 11, 14, 22, 13, 20, tzinfo=timezone.utc)
print(value.timestamp())
# 1700000000.0Seconds, milliseconds, and timezone-aware dates
Python's datetime.fromtimestamp() takes seconds. Divide a millisecond timestamp by 1,000 first. Pass timezone.utc explicitly when you want UTC; omitting the timezone uses the machine's local timezone and returns a naive datetime. The timestamp() method returns seconds, so multiply by 1,000 when your API expects milliseconds.
Named zones and daylight saving
The generated examples use zoneinfo, available in Python 3.9 and later. If the system has no timezone database, install the tzdata package. Convert a known instant into a named zone to obtain the appropriate offset. Assigning a zone to an arbitrary local datetime does not by itself validate a skipped time.
Use the time zone converter to check repeated and missing local times. Python examples support years 1–9999; generated output can depend on your installed timezone data.
Reference: Python datetime documentation.
Feedback
Have a suggestion, spotted a problem, or need another date format? Help shape what comes next for Timeplain.