DEV Community

楊東霖
楊東霖

Posted on • Originally published at devtoolkit.cc

How to Convert Unix Timestamp to Date: Complete Developer Guide

A Unix timestamp is the number of seconds (or milliseconds) elapsed since January 1, 1970, at 00:00:00 UTC — the Unix epoch. You will see Unix timestamps everywhere: API responses, database records, log files, JWT tokens, and analytics events. Knowing how to convert a Unix timestamp to a date is a fundamental developer skill. This guide shows you how to do it in JavaScript, Python, and with our free online tool.

Want to skip the code and convert a timestamp right now? Use our free Timestamp Converter — paste any Unix timestamp and get the human-readable date and time instantly, with timezone support.

What Is a Unix Timestamp?

The Unix timestamp (also called POSIX time or epoch time) is a system for describing a point in time as a single integer. It counts the number of seconds since 1970-01-01T00:00:00Z, which is called the Unix epoch.

For example:

  • 0 → 1970-01-01 00:00:00 UTC
  • 1000000000 → 2001-09-09 01:46:40 UTC
  • 1711238400 → 2024-03-24 00:00:00 UTC

Modern systems often use millisecond timestamps (multiplied by 1000). JavaScript's Date.now() returns milliseconds. Always check whether a timestamp is in seconds or milliseconds — a 13-digit number is almost certainly milliseconds; a 10-digit number is seconds.

How to Convert Unix Timestamp to Date in JavaScript

JavaScript's built-in Date object accepts millisecond timestamps in its constructor. If you have a seconds-based timestamp, multiply by 1000 first.

Seconds Timestamp to Date

const unixSeconds = 1711238400;
const date = new Date(unixSeconds * 1000); // Convert to milliseconds

console.log(date.toISOString());
// "2024-03-24T00:00:00.000Z"

console.log(date.toLocaleDateString('en-US'));
// "3/24/2024"

console.log(date.toLocaleString('en-US', { timeZone: 'America/New_York' }));
// "3/23/2024, 8:00:00 PM"
Enter fullscreen mode Exit fullscreen mode

Milliseconds Timestamp to Date

const unixMs = 1711238400000;
const date = new Date(unixMs); // No multiplication needed

console.log(date.toISOString());
// "2024-03-24T00:00:00.000Z"
Enter fullscreen mode Exit fullscreen mode

Format a Timestamp as a Readable String

function formatUnixTimestamp(unixSeconds) {
  const date = new Date(unixSeconds * 1000);
  return date.toLocaleString('en-US', {
    year: 'numeric',
    month: 'long',
    day: 'numeric',
    hour: '2-digit',
    minute: '2-digit',
    timeZoneName: 'short'
  });
}

console.log(formatUnixTimestamp(1711238400));
// "March 24, 2024 at 12:00 AM UTC"
Enter fullscreen mode Exit fullscreen mode

For more JavaScript date manipulation techniques, see our guide on converting timestamps in JavaScript.

How to Convert Unix Timestamp to Date in Python

Python's datetime module provides fromtimestamp() and utcfromtimestamp() for converting Unix timestamps.

Basic Conversion

from datetime import datetime, timezone

unix_seconds = 1711238400

# UTC datetime
utc_dt = datetime.fromtimestamp(unix_seconds, tz=timezone.utc)
print(utc_dt)
# 2024-03-24 00:00:00+00:00

# Local system timezone
local_dt = datetime.fromtimestamp(unix_seconds)
print(local_dt)
# 2024-03-23 20:00:00 (example for UTC-4)

# Formatted string
print(utc_dt.strftime('%B %d, %Y %H:%M:%S %Z'))
# March 24, 2024 00:00:00 UTC
Enter fullscreen mode Exit fullscreen mode

Milliseconds in Python

from datetime import datetime, timezone

unix_ms = 1711238400000

# Divide by 1000 to convert to seconds
utc_dt = datetime.fromtimestamp(unix_ms / 1000, tz=timezone.utc)
print(utc_dt.isoformat())
# 2024-03-24T00:00:00+00:00
Enter fullscreen mode Exit fullscreen mode

Convert Unix Timestamp in Other Contexts

SQL (PostgreSQL)

-- Seconds to timestamp
SELECT TO_TIMESTAMP(1711238400);
-- 2024-03-24 00:00:00+00

-- Current Unix timestamp
SELECT EXTRACT(EPOCH FROM NOW())::BIGINT;
-- 1711238400
Enter fullscreen mode Exit fullscreen mode

Bash / Shell

# Convert timestamp to date (Linux)
date -d @1711238400
# Sun Mar 24 00:00:00 UTC 2024

# macOS
date -r 1711238400
# Sun Mar 24 00:00:00 UTC 2024

# Current Unix timestamp
date +%s
# 1711238400
Enter fullscreen mode Exit fullscreen mode

Using the Online Timestamp Converter

When you just need a quick answer without writing code, our Timestamp Converter is the fastest option:

  • Paste your Unix timestamp into the input field (seconds or milliseconds — the tool auto-detects)
  • See the converted date and time in UTC, your local timezone, and ISO 8601 format instantly
  • Switch timezones using the dropdown to see the same moment in any timezone worldwide
  • Convert in reverse: pick a date and time to get the corresponding Unix timestamp

This is especially useful for reading JWT expiry timestamps, debugging log files with epoch times, or cross-checking scheduled job times.

Common Pitfalls When Converting Unix Timestamps

Seconds vs. Milliseconds Confusion

This is the most frequent mistake. If your conversion produces a date in the year 50000+, you passed milliseconds where seconds were expected. If your date is in 1970, you passed seconds where milliseconds were expected. A quick check: a 10-digit number is seconds; a 13-digit number is milliseconds.

Timezone Bugs

Unix timestamps are always UTC. The conversion to a local time depends on your system's timezone or the timezone you specify. Always be explicit about timezone when converting — never rely on system defaults in production code.

Year 2038 Problem

On 32-bit systems, a signed 32-bit integer can only hold timestamps up to 2147483647 (January 19, 2038 at 03:14:07 UTC). After that, it overflows. Modern 64-bit systems are not affected, but this matters for legacy embedded systems or old database schemas that store timestamps as INT(11).

Frequently Asked Questions

What is the current Unix timestamp?

The current Unix timestamp changes every second. Use our Timestamp Converter to see the current epoch time, or run Date.now() in a browser console (returns milliseconds) or date +%s in a terminal (returns seconds).

How do I convert a date back to a Unix timestamp?

In JavaScript: Math.floor(new Date('2024-03-24').getTime() / 1000). In Python: int(datetime(2024, 3, 24, tzinfo=timezone.utc).timestamp()). Our Timestamp Converter handles both directions.

Why is Unix time measured from 1970?

The Unix operating system was developed in the late 1960s and early 1970s. The developers chose January 1, 1970 as a convenient round number near the time they were working — there is no deeper mathematical reason. It became a universal standard as Unix spread.

Are Unix timestamps affected by leap seconds?

Technically, no. Unix timestamps treat every day as exactly 86,400 seconds, which means they do not account for the occasional leap second added to UTC to keep civil time aligned with the Earth's rotation. In practice, most systems handle this transparently and the difference is negligible for application development.

What is the maximum Unix timestamp?

On a 64-bit system, the maximum timestamp is 9223372036854775807, which corresponds to the year 292,277,026,596. In practical terms, 64-bit timestamps are effectively unlimited for any human-scale application.

Free Developer Tools

If you found this article helpful, check out DevToolkit — 40+ free browser-based developer tools with no signup required.

Popular tools: JSON Formatter · Regex Tester · JWT Decoder · Base64 Encoder

🛒 Get the DevToolkit Starter Kit on Gumroad — source code, deployment guide, and customization templates.

Top comments (0)