Seconds vs milliseconds
A 10-digit Unix timestamp is usually seconds. A 13-digit timestamp is usually milliseconds. Mixing them creates dates that look wildly wrong.
Unix timestamps are common in logs, APIs, and databases. This guide explains seconds vs milliseconds and how to convert epoch values to local time zones.
A 10-digit Unix timestamp is usually seconds. A 13-digit timestamp is usually milliseconds. Mixing them creates dates that look wildly wrong.
Most systems store timestamps in UTC. Convert to local time only for display, reports, customer support, or human scheduling.
When comparing logs across servers, convert every timestamp from UTC into the same target zone before comparing event order.
Copy a snippet and replace the timestamp or time zone with the values you need.
Convert epoch seconds to India time in the browser or Node.js.
const epochSeconds = 1700000000;
const date = new Date(epochSeconds * 1000);
console.log(date.toLocaleString('en-US', {
timeZone: 'Asia/Kolkata',
dateStyle: 'medium',
timeStyle: 'long',
}));Convert a Unix timestamp from UTC into a local IANA time zone.
from datetime import datetime, timezone
from zoneinfo import ZoneInfo
epoch_seconds = 1700000000
utc_time = datetime.fromtimestamp(epoch_seconds, tz=timezone.utc)
local_time = utc_time.astimezone(ZoneInfo("Asia/Kolkata"))
print(local_time.isoformat())Use java.time to convert epoch seconds into a ZonedDateTime.
import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;
Instant instant = Instant.ofEpochSecond(1700000000L);
ZonedDateTime localTime = instant.atZone(ZoneId.of("Asia/Kolkata"));
System.out.println(localTime);Convert epoch seconds to a local timestamp inside a query.
SELECT
to_timestamp(1700000000) AT TIME ZONE 'Asia/Kolkata'
AS india_time;Check an epoch value from macOS/BSD or Linux/GNU date.
# macOS / BSD
TZ=Asia/Kolkata date -r 1700000000
# Linux / GNU
TZ=Asia/Kolkata date -d @1700000000Unix time is the number of seconds since 1970-01-01 00:00:00 UTC, not counting leap seconds in most systems.
10 digits usually means seconds. 13 digits usually means milliseconds.
Use the timestamp as UTC first, then format it with an IANA time zone such as Asia/Kolkata, America/New_York, or Europe/London.
Usually no. Store in UTC and convert for display.