EpochTools

time and datetime modules

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

Real-world use cases for Python

  • Logging timestamps in a Django or Flask backend and converting them to readable dates for admin dashboards.
  • Normalizing datetimes scraped from different APIs into a single epoch column for time-series analysis with pandas.
  • Storing "valid until" timestamps for cached responses so the cache can expire without keeping timezone state.
Unix timestamp (seconds) ISO 8601 (UTC)
0 1970-01-01T00:00:00.000Z
946,684,800 2000-01-01T00:00:00.000Z
1,754,136,000 2025-08-02T12:00:00.000Z
2,147,483,647 2038-01-19T03:14:07.000Z
2,524,608,000 2050-01-01T00:00:00.000Z

These are the same fixed timestamps used in the Python examples above — every conversion returns one of these values.

Frequently asked questions

How do I get the current Unix timestamp in Python?

import time then int(time.time()) returns the current epoch in seconds. For milliseconds, multiply by 1000. The datetime module can also do it: int(datetime.now(timezone.utc).timestamp()).

How do I convert an epoch timestamp to a date in Python?

Use datetime.fromtimestamp(1754136000, tz=timezone.utc) to get a timezone-aware datetime in UTC, or pass a tzinfo for any IANA timezone. Call .isoformat() to serialize it.

What is the difference between time.time() and datetime.now()?

time.time() returns a raw float of epoch seconds, great for math and storage. datetime.now() returns a datetime object you can format, compare and localize. Convert between them with .timestamp() and datetime.fromtimestamp().

Epoch to human date in Python

Try it live — convert any timestamp in Python-friendly format.

Seconds or milliseconds — the unit is auto-detected. Example: 1735689600

Waiting for input…

UTC ISO 8601

–

Local — auto

–

RFC 2822 / GMT

–

Seconds value

–

Relative time

–

Other programming languages

Copy-paste epoch conversion snippets in your favorite stack

View all code snippets →

More timestamp guides

Example values used above: epoch seconds = 1,754,136,000 · ISO 8601 = 2025-08-02T12:00:00.000Z. Curious how the numbers work? See the Unix epoch time FAQ, or view the current epoch time in any timezone.