Skip to content
Devtoolry
Time & Scheduling

Unix Timestamps Explained: Seconds, Milliseconds and the Year 2038

What a Unix timestamp is, seconds vs milliseconds, converting in JavaScript, Python, Java, SQL and Excel, and the year 2038 problem.

Photo of Avinash KoriBy Avinash KoriPublished Updated 7 min read

A timeline from the Unix epoch in 1970 to the 32-bit overflow in January 2038, with today's timestamp marked

1792051200. To a computer that's a precise moment: 08:00 UTC on 15 October 2026. To a person reading a log file, an API response or a database row, it's just a big number until it is converted to a human-readable date. Unix timestamps are the most common way software stores time, and most date bugs start with a misunderstanding of what that number does and doesn't contain.

This guide explains Unix time, how to get the current timestamp, the seconds-versus-milliseconds trap, how to convert in the languages you use, and the overflow coming in 2038. To convert a value right now, paste it into the Unix Timestamp Converter, which also shows the current Unix time live.

What a Unix timestamp is

A Unix timestamp counts the seconds elapsed since 00:00:00 UTC on 1 January 1970, a moment called the Unix epoch. Times before the epoch are negative. The same count is also called Unix time, epoch time or POSIX time, because the POSIX standard defines it.

That definition has two consequences worth memorising:

  1. A timestamp has no time zone. It identifies one instant, the same everywhere on Earth. 1792051200 is 08:00 UTC, which is 09:00 in London (on British Summer Time in October), 13:30 in Mumbai and 04:00 in New York, all at the same instant. A time zone only matters when you display the timestamp.
  2. It's just an integer. Comparing, sorting and subtracting timestamps is trivial, which is exactly why databases, logs and protocols use them. The number of seconds between two events is one subtraction.

Paste any timestamp into the Unix time converter to see it as a date in any time zone, or watch the current Unix time tick.

Get the current Unix timestamp in code

To just see the number, the current Unix timestamp ticks live at the top of the converter. In a program, every platform has a one-liner for "now" in Unix time. All of these print the current time in seconds:

WhereCode
Linux or macOS shelldate +%s
JavaScriptMath.floor(Date.now() / 1000)
Pythonint(time.time()) (after import time)
PHPtime()
JavaInstant.now().getEpochSecond()
Ctime(NULL) (from <time.h>)
MySQLSELECT UNIX_TIMESTAMP();
PostgreSQLSELECT extract(epoch FROM now())::bigint;

Run two of them at the same moment and they agree, whatever time zone the machine is set to, because Unix time is always counted from UTC.

A few values are worth recognising when they turn up in logs and test data:

TimestampDate and time (UTC)
01 January 1970, 00:00:00 (the epoch)
10000000009 September 2001, 01:46:40
170000000014 November 2023, 22:13:20
200000000018 May 2033, 03:33:20
214748364719 January 2038, 03:14:07 (the 32-bit limit)

Seconds or milliseconds?

This is the bug everyone hits once. Unix time is defined in seconds, but many platforms use milliseconds:

PlatformUnitExample for the same moment
Unix, C, PHP time(), Python time.time() (float)seconds1792051200
JavaScript Date.now(), Java System.currentTimeMillis()milliseconds1792051200000
Some databases and APIsmicroseconds1792051200000000

The quickest way to tell them apart is length. Present-day timestamps in seconds have 10 digits; in milliseconds, 13; in microseconds, 16. (Seconds will gain an eleventh digit in the year 2286.)

Mixing them up gives absurd dates rather than errors:

JavaScript
new Date(1792051200 * 1000).toISOString(); // "2026-10-15T08:00:00.000Z" — correct
new Date(1792051200).toISOString();        // "1970-01-21T17:47:31.200Z" — seconds treated as ms

If a date shows up in January 1970, a value in seconds was treated as milliseconds. If it's tens of thousands of years in the future, it's the opposite. JWTs are a classic place for this bug: their exp and iat claims are in seconds, so Date.now() must be divided by 1000. Our JWT guide covers the details.

Converting in common languages

JavaScript

JavaScript
const nowSeconds = Math.floor(Date.now() / 1000);
const date = new Date(1792051200 * 1000);
date.toISOString();                                   // "2026-10-15T08:00:00.000Z"
date.toLocaleString('en-GB', { timeZone: 'Asia/Kolkata' }); // "15/10/2026, 13:30:00"
Math.floor(Date.parse('2026-10-15T08:00:00Z') / 1000); // 1792051200

Python

Python
from datetime import datetime, timezone

datetime.fromtimestamp(1792051200, tz=timezone.utc)  # 2026-10-15 08:00:00+00:00
int(datetime(2026, 10, 15, 8, 0, tzinfo=timezone.utc).timestamp())  # 1792051200

Always pass tz=timezone.utc to fromtimestamp. Without it, Python converts to the server's local time zone, so the same code gives different results on your laptop and in production. (datetime.utcfromtimestamp is deprecated since Python 3.12 because it returns a time without zone information.)

Java

java
import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;

Instant fromMillis = Instant.ofEpochMilli(1792051200000L);  // 2026-10-15T08:00:00Z
Instant fromSeconds = Instant.ofEpochSecond(1792051200L);   // the same instant

ZonedDateTime india = fromMillis.atZone(ZoneId.of("Asia/Kolkata"));
india;                  // 2026-10-15T13:30+05:30[Asia/Kolkata]
india.toLocalDate();    // 2026-10-15

fromMillis.toEpochMilli();   // 1792051200000
fromMillis.getEpochSecond(); // 1792051200

Instant.ofEpochMilli expects milliseconds, the unit of System.currentTimeMillis() and most Java and JavaScript timestamps; use ofEpochSecond for a 10-digit value. An Instant has no time zone, so call atZone(...) before asking for a local date or time, and keep the zone explicit instead of relying on ZoneId.systemDefault().

SQL

SQL
-- PostgreSQL
SELECT to_timestamp(1792051200);              -- 2026-10-15 08:00:00+00
SELECT extract(epoch FROM now())::bigint;

-- MySQL
SELECT FROM_UNIXTIME(1792051200);             -- in the session time zone
SELECT UNIX_TIMESTAMP();

Shell

Shell
date -u -d @1792051200       # GNU/Linux: Thu 15 Oct 2026 08:00:00 AM UTC
date -u -r 1792051200        # macOS/BSD
date +%s                     # current Unix time

Convert a Unix timestamp to a date in Excel or Google Sheets

Spreadsheets store dates as the number of days since 1899-12-30, with the time as a fraction of a day. A timestamp counts seconds since 1970-01-01, and the gap between the two starting points is 25,569 days. So the conversion is a division and an addition:

TaskFormula
Timestamp in seconds (A1) to date=A1/86400+25569
Timestamp in milliseconds (A1) to date=A1/86400000+25569
Date (A1) back to a timestamp in seconds=(A1-25569)*86400
Current Unix timestamp=(NOW()-25569)*86400 (NOW() is local time, so subtract your UTC offset in days)

Format the result cell as a date and time, for example yyyy-mm-dd hh:mm:ss, or you will see a number like 45244.9259259259. For the timestamp 1700000000, that number is the date 2023-11-14 22:13:20 UTC.

Two things trip people up. The formulas give UTC, not your local time: to show local time add your offset in days, such as +5.5/24 for India. And Excel keeps only 15 significant digits, so a timestamp in microseconds or nanoseconds loses precision; divide it down to seconds first. Google Sheets uses the same formulas. You can check any value with the Unix Timestamp Converter before you trust a column of them.

The date-only parsing trap

JavaScript has a surprise for anyone who parses a date without a time:

JavaScript
new Date('2026-10-15');        // midnight UTC
new Date('2026-10-15T00:00');  // midnight in the *local* time zone

Date-only ISO strings are parsed as UTC, while date-time strings without a zone are parsed as local time. A user in New York who picks 15 October in a date input and sees it formatted locally gets 14 October, 20:00. Birthdays shift by a day, and so do deadlines.

The fix depends on what you mean. If a date is a calendar date with no time (a birthday, a holiday), keep it as the string 2026-10-15 or as separate year, month and day values, and don't convert it to a timestamp at all. If it's a moment, always include the zone: 2026-10-15T00:00:00Z or 2026-10-15T00:00:00+05:30.

Leap seconds: Unix time pretends they don't exist

Since 1972, 27 leap seconds have been added to UTC to keep it aligned with the Earth's rotation. Unix time ignores them: every day is exactly 86,400 seconds. When a leap second happens, the Unix clock repeats a second or (on systems that "smear" leap seconds, as Google and AWS do) runs slightly slow for a few hours.

For almost all software this is a good trade: day arithmetic stays simple. It does mean that subtracting two timestamps can be off by a second across a leap second, which matters only in scientific and financial timing. The good news: leap seconds are scheduled to be abolished by 2035.

The year 2038 problem

Many older systems store Unix time in a signed 32-bit integer. Its maximum value, 2,147,483,647, corresponds to:

Output
2038-01-19T03:14:07Z

One second later the value overflows to −2,147,483,648, which is a date in December 1901. Software that still uses 32-bit time_t will think it has travelled back 136 years.

Most modern operating systems and languages already use 64-bit time, which lasts for about 292 billion years. The risks are in the places that are hard to update:

  • Embedded devices (routers, industrial controllers, cars) with 32-bit firmware.
  • File formats and protocols with 32-bit timestamp fields.
  • Database columns: MySQL's TIMESTAMP type is limited to 2038-01-19. Use DATETIME or BIGINT for dates beyond that. PostgreSQL's timestamptz is safe.
  • Code that already deals with the future today: 15-year certificates, 30-year mortgages and long-dated bonds cross 2038 now.

If you store timestamps yourself, use a 64-bit integer column, and test your code with dates after 2038.

Timestamps vs ISO 8601 strings

Unix timestamps are compact and easy to compute with, but unreadable. ISO 8601 strings (2026-10-15T08:00:00Z) are readable and still sort correctly as text, if they are all in UTC with the same precision. A common, sensible split:

  • Store and compute with timestamps or native database time types.
  • Exchange in APIs as ISO 8601 with an explicit offset or Z, so humans can read payloads and nobody has to guess the unit.
  • Display in the user's time zone, converted at the last moment.

When the display involves several zones, let a tool do the work: the Time Zone Converter handles daylight saving correctly, and Time zone and DST bugs explains what goes wrong when code does it by hand. For "how many days until…" questions, the Date Difference Calculator counts calendar days rather than dividing seconds by 86,400.

Timestamps describe single instants. Work that repeats on a calendar, such as "every weekday at 09:00" or "the first day of each month", is better described with a cron expression, which a scheduler turns into the next timestamp each time it runs.

Summary

A Unix timestamp is the number of seconds since 1970-01-01 UTC: one instant, with no time zone. Tell seconds (10 digits) from milliseconds (13 digits) by length, convert to local time only for display, include a zone whenever you parse a date-time, and store timestamps in 64-bit fields so 2038 is a non-event.

Photo of Avinash Kori

Written by

Avinash Kori

Founder of Devtoolry

Avinash is a full-stack web developer from Surat, India, with eight years of experience in PHP, Laravel and Angular. He built Devtoolry so developers can solve everyday problems quickly with free tools that run entirely in the browser, and writes practical guides on the formats, encodings and techniques behind them.

Connect on LinkedIn

Try it yourself

The free tools used in this article. They run in your browser, so nothing you paste is uploaded.