Knowledge base
Unix timestamp guide for developers
Use this page as a compact reference for handling timestamps correctly in APIs, logs, schedulers, and databases. For live conversion, open the Unix timestamp converter.
What a Unix timestamp represents
A Unix timestamp is a count of elapsed time since 1970-01-01 00:00:00 UTC. It represents one instant, not a calendar date in a particular city. Local time, UTC, and formatted strings are display choices applied after the instant is known.
Seconds vs milliseconds
Most current Unix seconds have 10 digits, while Unix milliseconds have 13 digits. JavaScript Date accepts milliseconds, but many APIs, databases, and log systems store seconds. Mixing the two can move dates into 1970 or thousands of years into the future.
UTC and timezone display
Store timestamps in UTC or as Unix time whenever possible. Convert to the viewer's timezone only at the presentation layer. If a business rule depends on a city or region, store the IANA timezone such as America/New_York, not just an offset like UTC-5.
Common mistakes checklist
- Passing Unix seconds directly into new Date(seconds) instead of new Date(seconds * 1000).
- Storing a recurring business event as a fixed UTC offset and then being surprised by daylight saving time.
- Removing the trailing Z from an ISO string and accidentally changing UTC into local browser time.
- Comparing formatted date strings instead of comparing numeric epoch milliseconds.
Copy-ready snippets
JavaScript
const iso = new Date(unixSeconds * 1000).toISOString();Python
dt = datetime.fromtimestamp(unix_seconds, tz=timezone.utc)Go
t := time.Unix(unixSeconds, 0).UTC()PostgreSQL
SELECT to_timestamp(1767225600) AT TIME ZONE 'UTC';