DEV Community

kingfujing
kingfujing

Posted on Originally published at devtoolshub.cloud

Convert Unix Timestamp to Date in Excel, Python and JavaScript

Originally published on DevToolsHub — free, privacy-first online tools for developers.

A Unix timestamp is just a number — 1764288000 — yet logs,
APIs, and databases are full of them. Every developer eventually has to
turn one of these values into an actual date, whether it is for a
spreadsheet report, a Python script, or a quick debugging session in the
browser console. The conversion itself is simple, but it hides two
classic traps: seconds versus milliseconds and
timezone handling. Get either one wrong and your
carefully computed date is off by a factor of a thousand or by a few
hours.

      This guide walks through the exact formulas and code you need in Excel,
      Python, JavaScript, and SQL — then shows you how to detect 10-digit vs
      13-digit values automatically, how to diagnose those frustrating
      "off by a few hours" results, and what the Year 2038 problem
      means for your systems.
Enter fullscreen mode Exit fullscreen mode

💡 Quick Try Paste any timestamp into our free

Unix Timestamp Converter

to convert it instantly — it auto-detects seconds vs milliseconds and
shows the result in UTC and your local time zone, right in your
browser.

What Is a Unix Timestamp?

      Unix time (also called POSIX time or epoch time) is the number of
      **seconds elapsed since 00:00:00 UTC on January 1, 1970** —
      a moment known as "the Unix epoch". It does not count leap
      seconds, and it is always expressed relative to UTC, never to a local
      time zone. That second point is the root of most conversion bugs: the
      number itself is timezone-free, but the moment you display it as a
      human-readable date, *something* has to pick a zone.



      For example, `1764288000` means exactly 1764288000 seconds
      after the epoch, which lands on `2025-11-28 00:00:00 UTC`. If
      you are sitting in UTC+8, that same instant is `08:00` on
      your wall clock — same timestamp, different presentation.
Enter fullscreen mode Exit fullscreen mode

Convert Unix Timestamp in Excel

      Excel stores dates internally as **serial numbers**: the
      count of days since January 1, 1900. So converting a Unix timestamp is
      just unit arithmetic — divide by the number of seconds in a day, then
      add the serial number of the epoch date:
Enter fullscreen mode Exit fullscreen mode
Seconds:      =A1/86400 + DATE(1970,1,1)
Milliseconds: =A1/86400000 + DATE(1970,1,1)
Enter fullscreen mode Exit fullscreen mode
      `86400` is 24 × 60 × 60, the number of seconds in a day, and
      `DATE(1970,1,1)` evaluates to serial number 25569 in the
      default 1900 date system. After entering the formula,
      **you must format the cell as a datetime** — otherwise you
      will see a bare number like `20420` instead of a date. Select
      the cell, press `Ctrl+1`, and pick a custom format such as
      `yyyy-mm-dd hh:mm:ss`.



      One important caveat: **Excel has no concept of time zones**
      in its date serial numbers. The formula above gives you the
      *UTC wall-clock time* of the timestamp. If you want to see the
      value in your local zone, add the offset yourself — for UTC+8 you would
      use `=A1/86400 + DATE(1970,1,1) + TIME(8,0,0)`. Excel simply
      displays whatever arithmetic produces, so the "local time" you
      see is exactly as local as you make it.
Enter fullscreen mode Exit fullscreen mode

Convert Unix Timestamp in Python

      Python's `datetime` module handles this cleanly, but the
      **timezone argument is the difference between correct and
      subtly-wrong output**. Always prefer an explicit zone:
Enter fullscreen mode Exit fullscreen mode
from datetime import datetime, timezone

ts = 1764288000

# UTC — the safe default for logs and APIs
dt_utc = datetime.fromtimestamp(ts, tz=timezone.utc)
print(dt_utc)                      # 2025-11-28 00:00:00+00:00

# Local machine zone — depends on server settings
dt_local = datetime.fromtimestamp(ts)
print(dt_local)                    # 2025-11-28 08:00:00 (on a UTC+8 box)

# For milliseconds, divide by 1000 (keep the fraction)
ts_ms = 1764288000000
dt_ms = datetime.fromtimestamp(ts_ms / 1000, tz=timezone.utc)

# ISO 8601 string for APIs
print(dt_utc.isoformat())          # 2025-11-28T00:00:00+00:00
Enter fullscreen mode Exit fullscreen mode
      Without `tz=timezone.utc`, `fromtimestamp()`
      returns a naive datetime in the machine's local zone — which is why
      the same script can produce different dates on your laptop and on a
      production server. For reverse conversion, use
      `int(dt.timestamp())` on an aware datetime.
Enter fullscreen mode Exit fullscreen mode

Convert Unix Timestamp in JavaScript

      JavaScript's `Date` constructor works in
      **milliseconds, not seconds** — this single fact causes
      more invalid-date bugs than anything else:
Enter fullscreen mode Exit fullscreen mode
const tsSeconds = 1764288000;
const date = new Date(tsSeconds * 1000);        // multiply!

console.log(date.toISOString());  // 2025-11-28T00:00:00.000Z (UTC)
console.log(date.toString());     // your local zone rendering

// A 13-digit millisecond value is used as-is
const dateMs = new Date(1764288000000);

// Common bug: passing seconds directly gives a date in 1970
new Date(1764288000).toISOString();  // 1970-01-21T10:04:48.000Z — wrong
Enter fullscreen mode Exit fullscreen mode
      `toISOString()` always outputs UTC with a `Z`
      suffix, while `toString()` and `toLocaleString()`
      render in the runtime's zone. Multiply by 1000 for 10-digit values,
      pass 13-digit values through unchanged, and your conversion is
      deterministic.
Enter fullscreen mode Exit fullscreen mode

Convert in SQL: MySQL and PostgreSQL

      In MySQL, `FROM_UNIXTIME()` converts a seconds-based
      timestamp into a datetime in the **session time zone**:
Enter fullscreen mode Exit fullscreen mode
-- MySQL (seconds)
SELECT FROM_UNIXTIME(1764288000);              -- session zone
SELECT CONVERT_TZ(FROM_UNIXTIME(1764288000), '+00:00', '+08:00');

-- PostgreSQL (seconds, returns timestamptz)
SELECT to_timestamp(1764288000);               -- 2025-11-28 00:00:00+00
SELECT to_timestamp(1764288000000 / 1000);     -- milliseconds: divide first
Enter fullscreen mode Exit fullscreen mode
      PostgreSQL's `to_timestamp()` returns a
      `timestamptz`, which the client renders in the session's
      `TimeZone` setting — the underlying instant is exact. In
      MySQL, check `@@time_zone` before trusting the display, and
      normalize milliseconds by dividing by 1000 on either engine.
Enter fullscreen mode Exit fullscreen mode

Seconds vs Milliseconds: 10-Digit vs 13-Digit

      Many systems (Java, JavaScript, .NET, most log pipelines) emit
      **millisecond** timestamps — 13 digits today instead of 10.
      Feeding milliseconds into a seconds-based converter produces dates
      roughly 30,000 years in the future; the reverse gives you January 1970.
      The good news: the digit count is a reliable discriminator. Current
      second-based values are 10 digits (until the year 2286), and
      millisecond values are 13 digits (until the year 33658). A simple
      heuristic covers virtually every real-world case:
      **if the absolute value is greater than 1e11, treat it as
      milliseconds**.
Enter fullscreen mode Exit fullscreen mode
function normalizeTimestamp(value) {
  const n = Number(value);
  // Above 1e11 means we are already in milliseconds
  const seconds = Math.abs(n) > 1e11 ? n / 1000 : n;
  return new Date(seconds * 1000);   // works for both 10 and 13 digits
}

normalizeTimestamp(1764288000);     // 2025-11-28T00:00:00.000Z
normalizeTimestamp(1764288000000);  // 2025-11-28T00:00:00.000Z
Enter fullscreen mode Exit fullscreen mode

Troubleshooting: Converted Time Is Off by a Few Hours

      When your result is *close but shifted by 1–14 hours*, it is
      almost never arithmetic — it is a time zone mismatch somewhere in the
      chain. Work through this checklist:




      -
        **Check where the rendering happens.** The timestamp is
        UTC-pure; only the display layer adds a zone. Compare
        `toISOString()` (UTC) with `toString()`
        (local) — if they differ by the expected offset, the math is fine.


      -
        **Check the server's zone, not yours.** A UTC
        production server and a UTC+8 laptop render the same
        `datetime.fromtimestamp(ts)` call differently. Pin the zone
        explicitly instead of relying on the environment.


      -
        **Check for double conversion.** If a producer already
        stored `2025-11-28 08:00` as if it were UTC, every consumer
        will shift it again. Fix the writer, not the readers.


      -
        **Check DST boundaries.** Offsets like America/New_York
        swing between UTC−5 and UTC−4 across the year; a constant offset will
        be wrong for part of the data. Use full zone names (
        `America/New_York`), never fixed offsets, for historical
        data.
Enter fullscreen mode Exit fullscreen mode

The Year 2038 Problem

      Classic 32-bit systems store Unix time as a signed 32-bit integer,
      which can only count to 2,147,483,647 seconds — a ceiling reached at
      **03:14:07 UTC on January 19, 2038**. One second later, the
      counter overflows and can wrap to a negative value, interpreted as a
      date in 1901. Embedded devices, legacy databases with 32-bit columns,
      and old file formats are the real exposure: your 64-bit laptop and
      modern languages are fine. Audit now if you maintain firmware, IoT
      devices, or long-lived infrastructure that will still be alive in 2038,
      and prefer 64-bit or unsigned storage for anything new. Note that
      millisecond timestamps in 32-bit signed integers overflow far sooner —
      they already rolled over in 1970-plus-24.8 days unless the language
      promotes them to 64 bits internally.
Enter fullscreen mode Exit fullscreen mode

Common Mistakes & How to Avoid Them

      -
        **Forgetting the ×1000 in JavaScript.**
        `new Date(1764288000)` interprets the value as
        milliseconds and returns a January 1970 date. Multiply seconds by
        1000, or normalize first with the 1e11 heuristic.


      -
        **Formatting an Excel result as a number.** After
        `=A1/86400 + DATE(1970,1,1)`, the cell shows a small
        integer unless you explicitly apply a datetime number format. The
        math is right; only the display is wrong.


      -
        **Trusting the local timezone by default.** Naive
        conversions (`datetime.fromtimestamp(ts)` without
        `tz`, `FROM_UNIXTIME` on an unknown session
        zone) produce machine-dependent output. Pass an explicit zone for
        anything shared or persisted.


      -
        **Converting with string parsing.** Turning a timestamp
        into a string like `2025-11-28 00:00:00` and then parsing
        it again without a zone suffix silently re-interprets it in another
        zone. Convert numbers to dates directly; keep ISO strings with an
        explicit `Z` or offset when strings are unavoidable.


      -
        **Assuming all timestamps are seconds.** Java,
        `System.currentTimeMillis()`, .NET, and most modern log
        pipelines emit milliseconds. Always run the 10 vs 13-digit check
        before converting a batch of values.
Enter fullscreen mode Exit fullscreen mode

Frequently Asked Questions

Why is my converted time off by a few hours?

A Unix timestamp is always UTC, but your display layer renders it
in a local time zone. If the result is shifted by exactly 1–14
hours, the arithmetic is correct and the zone is the culprit.
Compare toISOString() with toString() in
JavaScript, or pass tz=timezone.utc in Python, to
confirm. Servers in UTC and laptops in UTC+8 will disagree by
design — pin the zone explicitly wherever you convert.

How do I know if a timestamp is in seconds or milliseconds?

Count the digits. Current seconds-based timestamps have 10 digits
(e.g. 1764288000) and millisecond timestamps have 13 (e.g.
1764288000000). A robust rule: if the absolute value is greater
than 1e11, treat it as milliseconds and divide by 1000. Context
helps too — Java, JavaScript, and .NET APIs natively use
milliseconds, while Unix tooling, Python, and most databases use
seconds.

Does Excel work with timestamps before 1970?

Yes, with care. Negative timestamps (dates before the epoch) work
in the formula: subtracting enough seconds pushes the serial
number below 25569 and Excel still renders a valid date back to
1900 — for example =A1/86400 + DATE(1970,1,1) handles a negative
A1 fine. The real limits are Excel itself: the 1900 date system
cannot represent dates before March 1, 1900 correctly (and shows a
phantom February 29, 1900), so timestamps older than late 1899
will not convert. Formatting as datetime is still required for the
display.

What is the Year 2038 problem?

Systems storing Unix time in a signed 32-bit integer overflow at
03:14:07 UTC on January 19, 2038 — the counter wraps to a negative
number and dates jump back to 1901. 64-bit platforms and modern
languages are unaffected; the risk lives in embedded firmware,
legacy 32-bit database columns, and old file formats. If your
infrastructure will still run in 2038, audit it now and move to
64-bit time storage.

Can I convert timestamps inside JSON log files?

Yes — and you do not need a script. Paste the log line or the raw
value into our free

              Unix Timestamp Converter

            , which auto-detects seconds vs milliseconds and shows the result
            in UTC and your local zone. For bulk files, combine the 1e11
            heuristic with jq or a Python one-liner, then spot-check a few
            rows in the converter to make sure your pipeline is correct.








        **Related Tools:**
        [Unix Timestamp Converter](https://devtoolshub.cloud/tools/timestamp)

        [JSON Formatter](https://devtoolshub.cloud/tools/json-formatter)

        [UUID Generator](https://devtoolshub.cloud/tools/uuid-generator)
Enter fullscreen mode Exit fullscreen mode

Top comments (0)