T

developer-tools

How to convert a Unix timestamp to a date

A plain-English guide to converting Unix (epoch) timestamps to readable dates, handling seconds vs milliseconds, and going back from a date to a timestamp.

Updated 2026-06-05

You are looking at a number like 1767225600 in a server log, an API response, or a JWT token, and you want to know what date and time it represents. That number is a Unix timestamp — and converting it to a real date takes only a few seconds once you know what you are looking at.

This guide explains what a Unix timestamp is, how to decode one quickly, and how to avoid the most common mistake (seconds versus milliseconds).

What is a Unix timestamp?

A Unix timestamp (also called an epoch timestamp) is a count of seconds that have passed since 1 January 1970 at 00:00:00 UTC. That reference point is called the Unix epoch.

A few things that make Unix timestamps useful:

  • They are a single integer with no timezone embedded.
  • They sort correctly — a bigger number always means a later moment.
  • Every programming language and database understands them.

For example, 1767225600 represents 1 January 2026 at 00:00:00 UTC. You will see them in API responses, log files, JWT tokens, cache expiry headers, and database records.

How to convert a Unix timestamp to a date

The quickest way is to paste the number into a Unix timestamp converter. Enter the number, pick whether it is in seconds or milliseconds, and the tool shows the matching UTC date, local time, and ISO 8601 string.

If you prefer to do it in code:

JavaScript

const ts = 1767225600;
const date = new Date(ts * 1000); // multiply by 1000 because Date() expects milliseconds
console.log(date.toUTCString()); // "Wed, 01 Jan 2026 00:00:00 GMT"

Python

import datetime
ts = 1767225600
dt = datetime.datetime.fromtimestamp(ts, datetime.timezone.utc)
print(dt)  # 2026-01-01 00:00:00+00:00

Command line (macOS/Linux)

date -d @1767225600        # Linux
date -r 1767225600         # macOS

Seconds vs milliseconds (10 vs 13 digits)

This is the most common source of confusion. Some systems store timestamps in seconds (10 digits), while others use milliseconds (13 digits).

FormatExampleDigit count
Seconds176722560010
Milliseconds176722560000013

Date.now() in JavaScript returns milliseconds. Many Unix systems and databases use seconds. If your conversion gives a year far in the future (like 2026 becomes 57,000-something), you likely fed milliseconds to a function that expects seconds — or vice versa.

A quick rule: if the number has 13 digits, divide by 1000 before passing it to a seconds-based API.

function toDate(ts) {
  // handle both seconds and milliseconds
  const ms = ts > 1e11 ? ts : ts * 1000;
  return new Date(ms);
}

Converting a date back to a timestamp

Going from a human-readable date to a Unix timestamp is called “epoch encoding.” You need it when constructing API requests, setting expiry times, or writing to a database that stores integers.

JavaScript

const date = new Date('2026-01-01T00:00:00Z');
const ts = Math.floor(date.getTime() / 1000); // 1767225600

Python

import datetime, calendar
dt = datetime.datetime(2026, 1, 1, tzinfo=datetime.timezone.utc)
ts = calendar.timegm(dt.timetuple())  # 1767225600

Always specify the timezone when encoding. A date with no timezone is ambiguous — different machines may produce different results.

UTC vs your local time

A Unix timestamp has no timezone. It is always a count of seconds from the UTC epoch. The confusion arises when you display it: 1767225600 is midnight UTC on 1 Jan 2026, but in New York (UTC−5) it displays as 7 pm on 31 Dec 2025.

When debugging, it helps to always convert to UTC first. That removes local-clock differences from the equation.

console.log(new Date(1767225600 * 1000).toUTCString());
// "Wed, 01 Jan 2026 00:00:00 GMT"

console.log(new Date(1767225600 * 1000).toLocaleString());
// varies by browser timezone

Server-side code should almost always store and compare UTC timestamps to avoid daylight-saving bugs.

Where you meet Unix timestamps in practice

JWT tokens. JSON Web Tokens include iat (issued at) and exp (expires at) claims as Unix timestamps. If a request fails with token expired, decoding the exp field tells you exactly when it expired. Working with JWT tokens often means handling a lot of JSON — a JSON formatter helps when you need to inspect the decoded payload.

Server logs. Apache, Nginx, and many cloud services log request times as Unix timestamps. Converting them helps you match a log entry to a specific moment.

Databases. Columns typed as INTEGER or BIGINT often store timestamps. SQL provides FROM_UNIXTIME() (MySQL) or to_timestamp() (PostgreSQL) for conversion.

Cache and TTL headers. HTTP Expires headers and CDN configuration sometimes express expiry as a Unix timestamp.

Event-tracking systems. Analytics, monitoring, and audit-trail tools frequently store events as epoch integers to make sorting and range queries efficient.

Bottom line

A Unix timestamp is a count of seconds (or milliseconds) since 1 January 1970 UTC. To decode one: check how many digits it has (10 = seconds, 13 = milliseconds), then convert to UTC first to avoid timezone confusion. For a fast conversion without writing any code, the Unix timestamp converter handles both directions and shows both UTC and local time side by side.