timetz logotimetzConvert any timezone instantly
Guide

Unix Timestamp to Local Time

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.

UTC
Universal ยท UTC
12:56 PM
Sun, Jul 26
ยฑ0h
๐ŸŸข Working
Mumbai
India ยท Asia/Kolkata
6:26 PM
Sun, Jul 26
+5h30m
๐ŸŒ† Evening
New York
USA ยท America/New York
8:56 AM
Sun, Jul 26
-4h
๐ŸŒ… Early morning
London
UK ยท Europe/London
1:56 PM
Sun, Jul 26
+1h
๐ŸŸข Working
Quick answer

Key takeaways

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.

UTC first, local display later

Most systems store timestamps in UTC. Convert to local time only for display, reports, customer support, or human scheduling.

Debugging logs

When comparing logs across servers, convert every timestamp from UTC into the same target zone before comparing event order.

Developer examples

Code examples for epoch time conversion

Copy a snippet and replace the timestamp or time zone with the values you need.

JavaScript

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',
}));

Python

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())

Java

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);

PostgreSQL

Convert epoch seconds to a local timestamp inside a query.

SELECT
  to_timestamp(1700000000) AT TIME ZONE 'Asia/Kolkata'
    AS india_time;

Terminal

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 @1700000000

Frequently Asked Questions

What is Unix time?

Unix time is the number of seconds since 1970-01-01 00:00:00 UTC, not counting leap seconds in most systems.

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

10 digits usually means seconds. 13 digits usually means milliseconds.

How do I convert epoch time in code?

Use the timestamp as UTC first, then format it with an IANA time zone such as Asia/Kolkata, America/New_York, or Europe/London.

Should timestamps be stored in local time?

Usually no. Store in UTC and convert for display.