Copied!
Back
Time Tool

Timestamp Diff Calculator

Calculate the exact difference between two Unix timestamps, ISO 8601 dates, or human-readable date/time values. See results in days, hours, minutes, seconds, and milliseconds. Supports both 10-digit (seconds) and 13-digit (milliseconds) epoch timestamps. Perfect for debugging log files, measuring API response times, and calculating durations. All computation runs in your browser.

Last updated: May 2026 · Reviewed by FreeDevTool backend engineering team
timestamp-diff.tool

Working with timestamps — Unix epoch, ISO 8601, and the time-zone traps that haunt every backend

Time is the single most error-prone primitive in software. Time zones, daylight saving, leap seconds, leap years, locale calendars, and the inconsistent way languages handle "now" all combine into a category of bugs that show up at 02:00 on the second Sunday in March and again on the first Sunday in November. This guide is the working reference for the two formats you actually need (Unix epoch and ISO 8601), the duration calculations that bite teams, and the language-by-language code that does it correctly.

Unix epoch — what it actually is

Unix time is the number of seconds elapsed since 1970-01-01T00:00:00 UTC (the "epoch"). It is the universal time format in databases, APIs, log files, and inter-service messaging because it is:

The two common widths:

The Year-2038 problem (Y2K38)

A 32-bit signed integer storing seconds-since-1970 overflows on 2038-01-19T03:14:07 UTC. After that moment, naive 32-bit Unix time wraps to -2,147,483,648 (December 1901). This affects:

Modern systems use 64-bit time_t, which gives ~292 billion years of headroom. If you ship to embedded systems or maintain legacy software, audit for 32-bit time storage now — the failure mode is silent and starts hitting 30-year mortgages and 20-year insurance contracts already.

ISO 8601 — the human-readable companion

ISO 8601 is the international standard for date/time representation. The canonical forms:

Always include the timezone marker (Z or ±HH:MM). A bare 2026-05-02T14:30:00 is ambiguous — different parsers interpret it as UTC vs local vs throw an error.

Computing durations — the two correct approaches

Duration calculations work cleanly in two regimes:

  1. Fixed-length units (seconds, minutes, hours, days, weeks) — just subtract the timestamps and divide. A "day" in this regime is exactly 86,400 seconds, regardless of DST or calendar.
  2. Calendar units (months, years) — depend on which months are involved. "One month from January 31" can mean Feb 28, Mar 1, Mar 2, or Mar 3 depending on the rule. Use a real datetime library, not arithmetic.

The conversion table for fixed units:

UnitSecondsMilliseconds
Second11 000
Minute6060 000
Hour3 6003 600 000
Day86 40086 400 000
Week604 800604 800 000
30-day month (approx)2 592 0002 592 000 000
365-day year (approx)31 536 00031 536 000 000

Duration calculations across 6 languages

JavaScript:
const a = new Date('2026-05-02T09:00:00Z');
const b = new Date('2026-05-02T11:30:00Z');
const seconds = (b - a) / 1000;        // 9000
const minutes = seconds / 60;           // 150
const hours   = minutes / 60;           // 2.5
Python (use the standard library):
from datetime import datetime, timezone
a = datetime(2026, 5, 2, 9, 0, tzinfo=timezone.utc)
b = datetime(2026, 5, 2, 11, 30, tzinfo=timezone.utc)
delta = b - a                  # timedelta(seconds=9000)
print(delta.total_seconds())   # 9000.0
Go:
import "time"
a, _ := time.Parse(time.RFC3339, "2026-05-02T09:00:00Z")
b, _ := time.Parse(time.RFC3339, "2026-05-02T11:30:00Z")
diff := b.Sub(a)               // 2h30m0s
seconds := diff.Seconds()      // 9000
Java (java.time, since Java 8):
import java.time.*;
Instant a = Instant.parse("2026-05-02T09:00:00Z");
Instant b = Instant.parse("2026-05-02T11:30:00Z");
Duration d = Duration.between(a, b);   // PT2H30M
long secs = d.getSeconds();
Rust (chrono):
use chrono::{DateTime, Utc};
let a: DateTime<Utc> = "2026-05-02T09:00:00Z".parse().unwrap();
let b: DateTime<Utc> = "2026-05-02T11:30:00Z".parse().unwrap();
let d = b - a;                  // Duration
let secs = d.num_seconds();     // 9000
SQL (Postgres):
SELECT EXTRACT(EPOCH FROM ('2026-05-02 11:30:00+00'::timestamptz
                       -  '2026-05-02 09:00:00+00'::timestamptz))
AS seconds_diff;   -- 9000

Time-zone gotchas — what bites every team

Practical use cases for timestamp diff

Common timestamp mistakes

Frequently Asked Questions

How do I calculate the difference between two Unix timestamps?
Subtract one timestamp from the other to get the difference in seconds: diff = timestamp2 - timestamp1. Then convert: divide by 86,400 for days, 3,600 for hours, 60 for minutes. This tool does the conversion automatically and shows results in all units simultaneously.
What is a Unix epoch timestamp?
A Unix timestamp (POSIX time / epoch time) is the number of seconds elapsed since January 1, 1970 00:00:00 UTC. It's the universal standard for storing and comparing dates in programming. JavaScript uses millisecond timestamps (13 digits), while most Unix systems use seconds (10 digits). This tool auto-detects both formats.
What date formats are accepted?
This tool accepts: Unix timestamps in seconds (10 digits) or milliseconds (13 digits), ISO 8601 dates (2026-03-20T14:30:00Z), and common date strings (March 20, 2026, 2026/03/20). If a value looks like a number, it's treated as a timestamp; otherwise it's parsed as a date string.
Does this account for time zones?
Unix timestamps are always UTC-based, so timezone differences don't affect the calculation. When you enter human-readable dates, they're parsed in your browser's local timezone. For UTC-specific calculations, use ISO 8601 format with the Z suffix (e.g., 2026-03-20T09:00:00Z).
How accurate is this for very large time spans?
JavaScript's Date object is accurate to the millisecond for dates between approximately 271,821 BC and 275,760 AD. For practical purposes, this covers any realistic timestamp comparison. Note that "months" and "years" vary in length, so the tool shows exact units (days, hours, seconds) rather than approximate months.

Browse all 50 free developer tools

All tools run in your browser, no signup required, nothing sent to a server.