CURRENT EPOCH · EPOCHTIME.TOOLS · A PRECISION INSTRUMENT FOR TIME
Converter Batch Difference Blog
Languages
JavaScript Python TypeScript Go Rust Java PHP SQL Bash
Specialty
LDAP Timestamp .NET Ticks Chrome/WebKit Cocoa / Core Data Discord Timestamp Excel OADate Unix Hex
Standards
ISO 8601 Guide Year 2038 NTP Timestamp GPS Time Julian Day

Get current Unix timestamp

The `time` module gives you epoch seconds directly. The `datetime` module is more flexible for arithmetic.

Seconds (integer)

import time
int(time.time())
# → 1735689600

Seconds (float, with sub-second precision)

import time
time.time()
# → 1735689600.123456

Milliseconds

import time
int(time.time() * 1000)
# → 1735689600123

Nanoseconds (Python 3.7+)

import time
time.time_ns()
# → 1735689600123456789

Convert epoch to datetime

Use `datetime.fromtimestamp()` for local time or `datetime.utcfromtimestamp()` for UTC. Always specify the timezone explicitly to avoid confusion.

Epoch → UTC datetime (recommended)

from datetime import datetime, timezone
dt = datetime.fromtimestamp(1735689600, tz=timezone.utc)
print(dt.isoformat())
# → 2025-01-01T00:00:00+00:00

Epoch → local datetime

from datetime import datetime
dt = datetime.fromtimestamp(1735689600)
print(dt)  # In your machine's local time

Epoch → specific timezone

from datetime import datetime
from zoneinfo import ZoneInfo
dt = datetime.fromtimestamp(1735689600, tz=ZoneInfo("America/New_York"))
print(dt)
# → 2024-12-31 19:00:00-05:00

Convert datetime to epoch

Use `.timestamp()` — but make sure your datetime has timezone info, or Python will assume local time.

Current datetime → epoch

from datetime import datetime, timezone
int(datetime.now(timezone.utc).timestamp())
# → 1735689600

Specific date → epoch

from datetime import datetime, timezone
dt = datetime(2025, 1, 1, 0, 0, 0, tzinfo=timezone.utc)
int(dt.timestamp())
# → 1735689600

From a different timezone

from datetime import datetime
from zoneinfo import ZoneInfo
dt = datetime(2025, 1, 1, 0, 0, 0, tzinfo=ZoneInfo("America/New_York"))
int(dt.timestamp())
# → 1735707600 (5 hours later than UTC midnight)

Format datetime for display

Use `strftime()` for custom formats, or `isoformat()` for ISO 8601.

ISO 8601

from datetime import datetime, timezone
datetime.now(timezone.utc).isoformat()
# → "2025-01-01T00:00:00+00:00"

Custom format

from datetime import datetime, timezone
dt = datetime.fromtimestamp(1735689600, tz=timezone.utc)
dt.strftime("%Y-%m-%d %H:%M:%S %Z")
# → "2025-01-01 00:00:00 UTC"

RFC 2822 format

from email.utils import format_datetime
from datetime import datetime, timezone
format_datetime(datetime.now(timezone.utc))
# → "Wed, 01 Jan 2025 00:00:00 +0000"

Parse common formats

`datetime.fromisoformat()` handles ISO 8601. For other formats, use `strptime()` with the right pattern.

ISO 8601 (Python 3.11+)

from datetime import datetime
datetime.fromisoformat("2025-01-01T00:00:00+00:00")
# Python 3.11+ handles full ISO 8601 including Z suffix:
datetime.fromisoformat("2025-01-01T00:00:00Z")

Custom format

from datetime import datetime
datetime.strptime("2025-01-01 14:30", "%Y-%m-%d %H:%M")
# Note: result is naive (no timezone)

RFC 2822

from email.utils import parsedate_to_datetime
parsedate_to_datetime("Wed, 01 Jan 2025 00:00:00 GMT")

Common gotchas

Pitfalls to watch for when working with Python dates.

Naive vs aware datetimes

# A "naive" datetime has no tzinfo. A "naive" datetime
# can't be safely converted to epoch — Python assumes local time.
# ALWAYS make datetimes timezone-aware:
from datetime import datetime, timezone
good = datetime.now(timezone.utc)
bad = datetime.now()  # naive, avoid

datetime.utcnow() is deprecated

# Python 3.12+ deprecates utcnow() because it returns naive UTC.
# Use this instead:
from datetime import datetime, timezone
datetime.now(timezone.utc)

zoneinfo vs pytz

# zoneinfo (stdlib, Python 3.9+) is the recommended choice.
# pytz is the older library — it works but has quirky API.
# For new code, use zoneinfo:
from zoneinfo import ZoneInfo
ZoneInfo("America/New_York")

Use the converter

Need to quickly check what a specific timestamp converts to? Use the main converter — paste any value and get every format back.

Working with many timestamps at once? Try the batch converter — paste a list, get a CSV or JSON file back.