A Unix timestamp looks like the simplest possible way to store a moment in time: one integer, no time zone, no formatting. That simplicity is why it's everywhere, from log files and JWT expiry claims to database columns and file systems. But the simple integer hides some real decisions: what happens to leap seconds, which unit the number is in, and how many bits it's stored in. Get them wrong and you get dates in 1970, events that happen twice, or software that fails in January 2038. This guide explains what Unix time actually counts, how to convert it safely in JavaScript, Python, and SQL (every snippet below was run before publishing), and what the 2038 problem is and isn't. To convert a specific value as you read, keep our Unix Timestamp Converter open in another tab.

Key Takeaways
  • Unix time counts seconds since 1970-01-01 00:00:00 UTC, treating every day as exactly 86,400 seconds, so leap seconds aren't counted.
  • A timestamp has no time zone. It names one instant everywhere; the zone only matters when you display it.
  • Today's timestamps have 10 digits in seconds, 13 in milliseconds, 16 in microseconds. Mixing units is the most common bug.
  • A signed 32-bit counter overflows after 2038-01-19 03:14:07 UTC and wraps to December 1901.
  • 64-bit systems are safe, and Linux has supported 64-bit time on 32-bit hardware since kernel 5.6, but databases, file formats, and embedded devices can still carry 32-bit time.
Advertisement

What a Unix Timestamp Counts

The Unix epoch is midnight UTC on January 1, 1970. A Unix timestamp is the number of seconds between that instant and the moment you care about. Positive values are after the epoch; negative values are before it. A few reference points:

TimestampUTC date and time
01970-01-01 00:00:00
10000000002001-09-09 01:46:40
17000000002023-11-14 22:13:20
17934048002026-10-31 00:00:00
21474836472038-01-19 03:14:07 (largest signed 32-bit value)
-21474836481901-12-13 20:45:52 (smallest signed 32-bit value)

Because the count is anchored to UTC, the same timestamp describes the same instant in Tokyo and Toronto. That makes it ideal for storing and comparing events, sorting logs, and computing durations, as long as you remember the caveat in the next section.

Leap Seconds: The Part Unix Time Ignores

Earth's rotation isn't perfectly steady, so UTC has occasionally inserted a leap second (a 61-second minute, ending at 23:59:60) to keep clock time close to solar time. POSIX, the standard that defines Unix time, deals with this by declining to count them. Its definition of Seconds Since the Epoch states that every day is accounted for by exactly 86,400 seconds, and it leaves the alignment with the real clock to the implementation.

The practical effect: a Unix timestamp is better thought of as an encoding of a UTC calendar date and time than as a true stopwatch reading. The last leap second was inserted at the end of 2016. 1483228799 is 2016-12-31 23:59:59 and 1483228800 is 2017-01-01 00:00:00; the leap second 23:59:60 between them has no timestamp of its own. Systems handled it differently. Some kernels repeated a second, which can make durations come out negative. Large operators such as Google instead "smear" the leap second, slowing their clocks very slightly over 24 hours so that no second repeats.

This may stop mattering. In 2022 the General Conference on Weights and Measures resolved to raise the allowed gap between UTC and astronomical time by 2035 or earlier, which would effectively end new leap seconds. For everyday code, the lesson is simple: for sub-second precision across a leap second, or for measuring elapsed time inside one process, use a monotonic clock (performance.now() in JavaScript, time.monotonic() in Python), not wall-clock timestamps.

Seconds, Milliseconds, Microseconds, Nanoseconds

"Unix time" traditionally means seconds, but many platforms use finer units. The number of digits is the fastest way to tell them apart for any date in the current era:

UnitDigits todayTypical sources
Seconds10C time(), shell date +%s, JWT exp/iat claims, Python int(time.time())
Milliseconds13JavaScript Date.now(), Java System.currentTimeMillis()
Microseconds16Many database and tracing systems
Nanoseconds19Go UnixNano(), Python time.time_ns()

Seconds stay at 10 digits until 2286-11-20 17:46:40 UTC, when they reach 10,000,000,000. The classic bug is passing seconds to an API that expects milliseconds. JavaScript's Date takes milliseconds, so this lands a 2023 timestamp in January 1970:

new Date(1700000000).toISOString(); // '1970-01-20T16:13:20.000Z' (wrong unit) new Date(1700000000 * 1000).toISOString(); // '2023-11-14T22:13:20.000Z' (correct)

One more JavaScript trap: numbers are 64-bit floats, exact only up to 253 (about 9.007 × 1015). Millisecond and microsecond timestamps fit; nanosecond timestamps (about 1.79 × 1018 today) don't. Parse nanosecond values as BigInt or as strings.

Time Zones: Only at the Edges

A timestamp has no time zone, but every human-readable date does. The safe pattern is to store and compute in UTC (or raw timestamps) and convert to a local zone only when displaying. Use IANA zone names such as America/New_York rather than fixed offsets like -05:00, because offsets change with daylight saving time and with local law.

Daylight saving time creates two edge cases when you go the other way, from a local time to a timestamp. In the spring, a local time like 2:30 a.m. may not exist; in the fall, 1:30 a.m. may happen twice. A local time without a zone and a rule for these cases is ambiguous, which is why the converter flags such times.

Converting in JavaScript, Python, and SQL

JavaScript

// Current time in seconds (Date.now() is milliseconds) const nowSeconds = Math.floor(Date.now() / 1000); // Timestamp to ISO 8601 (UTC) new Date(1700000000 * 1000).toISOString(); // '2023-11-14T22:13:20.000Z' // Display in a specific zone new Date(1700000000 * 1000).toLocaleString('en-US', { timeZone: 'America/New_York' }); // '11/14/2023, 5:13:20 PM' // UTC date to timestamp (months are 0-based: 9 = October) Date.UTC(2026, 9, 31) / 1000; // 1793404800 new Date('2026-10-31T00:00:00Z').getTime() / 1000; // 1793404800

Watch the parser: new Date('2026-10-31') (date only) is read as UTC midnight, but new Date('2026-10-31T00:00') (date and time, no zone) is read as local midnight. Always include a Z or an offset when you mean a specific instant.

Python

import time from datetime import datetime, timezone from zoneinfo import ZoneInfo int(time.time()) # current time in seconds datetime.fromtimestamp(1700000000, tz=timezone.utc) # 2023-11-14 22:13:20+00:00 datetime.fromtimestamp(1700000000, tz=ZoneInfo("America/New_York")) # 2023-11-14 17:13:20-05:00 datetime(2026, 10, 31, tzinfo=timezone.utc).timestamp() # 1793404800.0 datetime.fromtimestamp(1700000000123 / 1000, tz=timezone.utc) # from milliseconds

Always pass tz=. A "naive" datetime (no tzinfo) is interpreted in the machine's local zone by .timestamp() and fromtimestamp(), so the same code gives different answers on a laptop and a UTC server. datetime.utcfromtimestamp() is deprecated as of Python 3.12 for exactly this reason.

SQL

-- SQLite (unixepoch() requires SQLite 3.38+) SELECT datetime(1700000000, 'unixepoch'); -- 2023-11-14 22:13:20 SELECT unixepoch('2026-10-31 00:00:00'); -- 1793404800 SELECT strftime('%s', '2026-10-31 00:00:00'); -- '1793404800' (as text) -- PostgreSQL SELECT to_timestamp(1700000000); -- timestamptz SELECT extract(epoch FROM now()); -- seconds, with fraction -- MySQL SELECT FROM_UNIXTIME(1700000000); -- shown in the session time zone SELECT UNIX_TIMESTAMP();

The SQLite lines were run in SQLite 3.54; the PostgreSQL and MySQL lines use those databases' documented functions. Note that MySQL's FROM_UNIXTIME returns a value in the session's time zone, not UTC.

The Year 2038 Problem

For decades, the C type time_t that holds Unix time was a signed 32-bit integer on most systems. The largest value it can hold is 2,147,483,647, which is 2038-01-19 03:14:07 UTC. One second later, the counter overflows and wraps to −2,147,483,648, which software reads as 1901-12-13 20:45:52 UTC. You can watch the wrap in JavaScript with a 32-bit typed array:

const t = new Int32Array(1); t[0] = 2147483647; new Date(t[0] * 1000).toISOString(); // '2038-01-19T03:14:07.000Z' t[0] += 1; // overflow: wraps to -2147483648 new Date(t[0] * 1000).toISOString(); // '1901-12-13T20:45:52.000Z'

An unsigned 32-bit counter would last until 2106-02-07 06:28:15 UTC but can't represent dates before 1970. A signed 64-bit counter lasts roughly 292 billion years, which is why "move to 64-bit time" is the standard fix.

What has already been fixed

What can still break

The failures don't wait for 2038. Any system that calculates future dates already crosses the line: a 15-year loan schedule, a long-lived certificate, or a "never expires" sentinel set far in the future. A related but separate rollover is the Network Time Protocol's 32-bit seconds count from 1900, whose first era ends on 2036-02-07 06:28:16 UTC; the protocol is designed to handle eras, but naive implementations may not.

How to test your own code

Timestamps rarely travel alone. In APIs they sit inside JSON payloads and JWTs, which are Base64-encoded, and they often appear in query strings, where URL encoding rules apply to any ISO date with a + offset. If you're pulling timestamps out of log lines, a regular expression like \b\d{10}(?:\d{3})?\b finds 10- and 13-digit values.

Frequently Asked Questions

Is Unix time the same as UTC?

Almost. Unix time is derived from UTC and agrees with it at every whole second, except that it has no way to represent a leap second like 23:59:60. For nearly all applications you can treat them as interchangeable.

How can I tell whether a timestamp is in seconds or milliseconds?

Count the digits. For current dates, 10 digits means seconds, 13 milliseconds, 16 microseconds, and 19 nanoseconds. Our converter detects the unit automatically using the same idea.

Will my computer stop working in 2038?

A modern 64-bit computer and operating system won't have a problem with its own clock. The risk sits in older 32-bit embedded devices, legacy software, and data formats or database columns that still store time in 32 bits.

Can Unix timestamps be negative?

Yes. Negative values represent moments before 1970. For example, −86,400 is 1969-12-31 00:00:00 UTC. Some older systems and unsigned fields can't store them, so test if you handle historical dates.

Should I store dates as timestamps or as date strings?

For instants (when something happened), store a UTC timestamp or a time-zone-aware type. For calendar dates without a time, such as a birthday, store a date type. Converting a birthday to midnight in one zone can shift it a day when shown in another.