Learn how to convert epoch timestamps to readable dates and back. Clear steps, common pitfalls, best practices, and code examples in JavaScript, Python, SQL, Bash, Java, Go, and C#. Optimized for humans and search.
Introduction
Converting epoch timestamps is a daily task for developers, analysts, and SREs. If you’ve ever asked how to epoch timestamp convert to a readable date (or back), this guide is for you. We’ll cover UTC vs local time, seconds vs milliseconds, ISO 8601, and how to do it in your favorite languages. Plain, practical, and precise.
Featured Snippet (Quick Answer)
To convert an epoch timestamp to a date, know its unit. If seconds, convert directly; if milliseconds, divide by 1000. Use UTC for storage and convert to local time only for display. Example (JavaScript): new Date(1700000000 * 1000).toISOString(). To convert a date to epoch, parse it as UTC and take seconds: Math.floor(new Date("2024-11-14T00:00:00Z").getTime() / 1000).
Key Takeaways
AI Overview (Summary)
Epoch timestamps represent time as a single integer since 1970-01-01T00:00:00Z. To convert epoch to a date, know whether the value is in seconds or milliseconds and use built-in time libraries. Store UTC as a numeric epoch for speed and consistency, format user-facing times in ISO 8601, and avoid mixing local time in storage. Common pitfalls include unit confusion, DST issues, and time zone offsets. Use online tools, CLI utilities, and language helpers for reliable conversions.
Table of Contents
What is epoch timestamp convert
Epoch time (also called Unix time or POSIX time) is the number of seconds since the Unix epoch: 1970-01-01T00:00:00Z (UTC), ignoring leap seconds. Many systems also use milliseconds since epoch (ms). “Epoch timestamp convert” means turning this integer into a readable date/time and back.
Important concepts:
Why it Matters
Benefits
Step-by-Step Guide
Tip: Always label units in API docs and database schemas.
JavaScript (Node.js / Browser)
// Seconds to ISO 8601 UTC
const epochSec = 1700000000;
const isoUtc = new Date(epochSec * 1000).toISOString();
// Milliseconds to local string
const epochMs = 1700000000000;
const local = new Date(epochMs).toLocaleString();
Python 3
import datetime
# Seconds to UTC ISO
epoch_sec = 1700000000
iso_utc = datetime.datetime.utcfromtimestamp(epoch_sec).isoformat() + 'Z'
# Milliseconds to local
epoch_ms = 1700000000000
local_dt = datetime.datetime.fromtimestamp(epoch_ms / 1000)
Bash (GNU date)
# Seconds to UTC
E=1700000000; date -u -d @"$E" +"%Y-%m-%dT%H:%M:%SZ"
# Milliseconds to UTC (divide by 1000)
EM=1700000000000; date -u -d @"$((EM/1000))" +"%Y-%m-%dT%H:%M:%SZ"
SQL (PostgreSQL)
-- Seconds to timestamp with time zone (UTC by default)
SELECT to_timestamp(1700000000) AT TIME ZONE 'UTC' AS ts_utc;
-- Milliseconds
SELECT to_timestamp(1700000000000 / 1000.0) AT TIME ZONE 'UTC' AS ts_utc;
Java (java.time)
import java.time.*;
long epochSec = 1700000000L;
Instant instant = Instant.ofEpochSecond(epochSec);
String iso = instant.toString(); // UTC ISO 8601
long epochMs = 1700000000000L;
Instant instantMs = Instant.ofEpochMilli(epochMs);
ZonedDateTime local = instantMs.atZone(ZoneId.systemDefault());
Go
package main
import (
"fmt"
"time"
)
func main() {
sec := int64(1700000000)
t := time.Unix(sec, 0).UTC()
fmt.Println(t.Format(time.RFC3339))
}
C# (.NET)
long sec = 1700000000;
var dtUtc = DateTimeOffset.FromUnixTimeSeconds(sec).UtcDateTime; // ISO: dtUtc.ToString("O")
PHP
$sec = 1700000000;
echo gmdate('c', $sec); // ISO 8601 in UTC
JavaScript
// Date string (UTC) to epoch seconds
const iso = "2026-03-04T12:30:00Z";
const epochSec = Math.floor(new Date(iso).getTime() / 1000);
Python 3
import datetime
dt = datetime.datetime.fromisoformat("2026-03-04T12:30:00+00:00")
epoch_sec = int(dt.timestamp())
Bash (GNU date)
date -u -d "2026-03-04T12:30:00Z" +%s
PostgreSQL
SELECT EXTRACT(EPOCH FROM TIMESTAMPTZ '2026-03-04 12:30:00+00');
Java
Instant instant = Instant.parse("2026-03-04T12:30:00Z");
long epochSec = instant.getEpochSecond();
Go
layout := time.RFC3339
s := "2026-03-04T12:30:00Z"
t, _ := time.Parse(layout, s)
sec := t.Unix()
C#
var dto = DateTimeOffset.Parse("2026-03-04T12:30:00Z");
long epochSec = dto.ToUnixTimeSeconds();
Examples
JavaScript
const epochSec = 1700000000;
const tz = 'America/New_York';
const fmt = new Intl.DateTimeFormat('en-US', { timeZone: tz, dateStyle: 'medium', timeStyle: 'long' });
console.log(fmt.format(new Date(epochSec * 1000)));
Python (pytz or zoneinfo in Python 3.9+)
from datetime import datetime
from zoneinfo import ZoneInfo
t = datetime.fromtimestamp(1700000000, tz=ZoneInfo("UTC"))
local = t.astimezone(ZoneInfo("America/New_York"))
Warning: Unit confusion is the #1 cause of bad dates.
Examples
Real World Examples
Example: Bucketing events hourly (Python)
bucket = epoch_sec - (epoch_sec % 3600) # start of the hour (UTC)
Example: JWT exp validation (JavaScript)
const now = Math.floor(Date.now() / 1000);
if (jwtPayload.exp && jwtPayload.exp < now) throw new Error('Token expired');
Common Mistakes
Best Practices
Expert Tips
Comparison Table
| Method / Tool | Units | Time Zone Handling | Pros | Cons | Best For |
|---|---|---|---|---|---|
| JavaScript Date/Intl | s, ms | Local and IANA via Intl | Built-in, easy in browsers/Node | Legacy Date quirks | Web apps, quick UI conversions |
| Python datetime/zoneinfo | s, ms | Strong tz via zoneinfo | Clear API, great for scripts | Requires care with naive vs aware | Data scripts, ETL, automation |
| Bash date | s (ms via div) | System tz or -u for UTC | One-liners, great in CI/CD | Platform differences (BSD vs GNU) | DevOps, shell pipelines |
| PostgreSQL | s, ms | AT TIME ZONE | Powerful queries, indexing | SQL dialect specifics | Analytics, dashboards, data warehousing |
| Java java.time | s, ms, ns | Strong tz w/ ZoneId | Modern API, thread-safe | Verbose for simple tasks | Enterprise backends |
| C# DateTimeOffset | s, ms | Offset-aware | Clear epoch conversion methods | Need to avoid DateTime (unspecified) | .NET services |
| Go time | s, ns | Location with tzdata | Simple, fast, precise | Tzdata management in containers | CLIs, microservices |
| Online converter (tool) | s, ms, more | Quick switch local/UTC | Zero setup, visual check | Manual step, browser needed | Quick checks, non-dev users |
Internal Link Suggestions
External References
Frequently Asked Questions
An epoch timestamp is a numeric count of seconds (or milliseconds) since 1970-01-01T00:00:00Z (UTC). It’s a compact, universal way to represent time.
Check the length. 10 digits usually means seconds; 13 digits means milliseconds. If unsure, convert both ways and sanity-check the resulting date.
Use your language’s date library. Example (Python): datetime.utcfromtimestamp(1700000000).isoformat() + 'Z'. Or use an online converter.
Parse the ISO 8601 string in UTC, then take the epoch. Example (JS): Math.floor(new Date("2026-03-04T12:30:00Z").getTime()/1000).
Store UTC. Convert to the user’s time zone only for display. This avoids DST and offset errors.
It’s a standard date format like 2026-03-04T12:30:00Z. It is unambiguous and works well across systems and languages.
You likely treated milliseconds as seconds. Divide by 1000 before converting.
Unix time ignores leap seconds, treating each day as exactly 86,400 seconds.
Legacy 32-bit systems store seconds in a signed 32-bit int. It overflows on 2038-01-19. Use 64-bit time types to avoid this.
Store UTC. When showing times, convert to the target IANA time zone. Let libraries handle DST rules.
Yes. Epoch is numeric, so sorting and indexing are fast in databases and code.
PostgreSQL: to_timestamp(epoch_s). For milliseconds: to_timestamp(epoch_ms/1000.0). Use AT TIME ZONE for conversion.
Keep a high-precision integer (us/ns). For display, convert to seconds plus fractional part. Many languages support nanos.
Use Intl.DateTimeFormat().resolvedOptions().timeZone and format with that zone for display.
Specify UTC, the unit (seconds or ms), and the format for any strings (ISO 8601). Include examples and edge-case notes.
Conclusion
Epoch time is simple, fast, and portable. When you standardize on UTC, use ISO 8601 for strings, and document units, you avoid most time bugs. With the examples and best practices here, you can convert, display, and store times with confidence across systems and time zones.
Call To Action
Ready to simplify date handling? Use ZenixTools’ free Epoch Converter to test values, compare UTC and local outputs, and generate ISO 8601 strings. Keep your apps fast and accurate—start your next epoch timestamp convert in seconds.
Learn how to convert 1 meter to feet with precise formulas, quick methods, and real-world examples. Includes best practices, common mistakes, comparison tables, FAQs, and expert tips for accurate length conversions.
Master converting from kilometers to miles with exact formulas, quick mental math, charts, and real examples. Written for travelers, runners, students, and pros.