A practical, human-friendly guide to convert epoch time to readable dates and back—using online tools, code, spreadsheets, and CLI. Includes examples, best practices, and FAQs.
If you need to convert epoch time for logs, APIs, or spreadsheets, you’re in the right place. This guide shows exactly how to convert epoch time to a readable date—and back again—using online tools, code snippets, terminal commands, and popular databases. You’ll also learn common pitfalls (like seconds vs. milliseconds) and how to avoid them.
Epoch time (Unix timestamp) counts seconds since 1970-01-01 00:00:00 UTC. To convert epoch time to a human-readable date, divide by 1000 if your value is in milliseconds, then format the date in UTC or your local time zone. Common methods: JavaScript new Date(epoch*1000), Python datetime.fromtimestamp(epoch, tz), and SQL to_timestamp(epoch) for seconds.
This guide explains epoch time, why it matters, and how to convert it reliably. Learn quick web, CLI, and spreadsheet methods; see code in JavaScript, Python, Java, Bash, SQL, and Go; and explore real use cases (APIs, logs, databases, IoT). You’ll avoid top mistakes (ms vs s, time zones, DST), follow best practices (UTC, ISO 8601), and find expert tips for performance and accuracy. Includes comparison tables, FAQs, and links to trusted documentation.
“Convert epoch time” is a common phrase for turning a Unix timestamp (seconds since 1970-01-01 00:00:00 UTC) into a readable date, or converting a human date back to an epoch timestamp. You might also see related terms: Unix timestamp, epoch, POSIX time, or seconds since 1970.
Note: Some systems and APIs use milliseconds instead of seconds. That’s the #1 source of confusion when you convert epoch time.
Here’s the quick conversion cheat sheet for seconds-based epoch values:
Tip: Always decide if your output should be in UTC or local time.
Note: Online tools are great for quick checks and debugging.
const epochSeconds = 1697040000;
const dt = new Date(epochSeconds * 1000);
dt.toISOString(); // UTC ISO 8601
dt.toString(); // Local time string
const epochMillis = 1697040000000;
new Date(epochMillis).toISOString();
const iso = '2023-10-11T00:00:00Z';
const epochSec = Math.floor(new Date(iso).getTime() / 1000);
Warning: JavaScript Date stores milliseconds since epoch. Be careful not to multiply by 1000 twice.
from datetime import datetime, timezone
# Epoch seconds to UTC datetime
epoch = 1697040000
utc_dt = datetime.fromtimestamp(epoch, tz=timezone.utc)
print(utc_dt.isoformat()) # 2023-10-11T00:00:00+00:00
# UTC datetime to epoch seconds
dt = datetime(2023, 10, 11, 0, 0, 0, tzinfo=timezone.utc)
print(int(dt.timestamp())) # 1696982400 (example)
# If you have milliseconds
epoch_ms = 1697040000000
utc_dt_ms = datetime.fromtimestamp(epoch_ms / 1000, tz=timezone.utc)
print(utc_dt_ms.isoformat())
Tip: Always set tz=timezone.utc for consistent results.
date -u -d @1697040000
date -d @1697040000
date -u -d @1697040000 +"%Y-%m-%dT%H:%M:%SZ"
date +%s
date -u -d "2023-10-11 00:00:00" +%s
Note: BSD/macOS date uses different flags. On macOS:
# seconds to date (UTC)
date -u -r 1697040000
# date to epoch (UTC)
date -u -j -f "%Y-%m-%d %H:%M:%S" "2023-10-11 00:00:00" +%s
-- seconds to timestamp (with time zone awareness)
SELECT to_timestamp(1697040000) AT TIME ZONE 'UTC';
-- timestamp to epoch seconds
SELECT EXTRACT(EPOCH FROM TIMESTAMPTZ '2023-10-11 00:00:00+00');
SELECT FROM_UNIXTIME(1697040000); -- local time zone of server
SELECT CONVERT_TZ(FROM_UNIXTIME(1697040000), '+00:00', '+00:00'); -- force UTC
SELECT UNIX_TIMESTAMP('2023-10-11 00:00:00'); -- to epoch seconds
SELECT datetime(1697040000, 'unixepoch'); -- UTC by default
SELECT strftime('%s', '2023-10-11 00:00:00'); -- to epoch seconds
Warning: Server time zones can affect outputs. Force UTC when consistency matters.
import java.time.Instant;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
long epochSeconds = 1697040000L;
Instant instant = Instant.ofEpochSecond(epochSeconds);
String isoUtc = DateTimeFormatter.ISO_INSTANT.format(instant); // 2023-10-11T00:00:00Z
// Epoch milliseconds to Instant
long epochMillis = 1697040000000L;
Instant i2 = Instant.ofEpochMilli(epochMillis);
// Instant to epoch seconds
long backToSeconds = instant.getEpochSecond();
package main
import (
"fmt"
"time"
)
func main() {
sec := int64(1697040000)
t := time.Unix(sec, 0).UTC()
fmt.Println(t.Format(time.RFC3339))
// millis
ms := int64(1697040000000)
t2 := time.Unix(0, ms*int64(time.Millisecond)).UTC()
fmt.Println(t2.Format(time.RFC3339))
// back to epoch seconds
fmt.Println(t.Unix())
}
Tip: Excel stores dates as days since 1899-12-30; the division by 86400 converts seconds to days.
{ "created_at": 1697040000 }
dt = datetime.fromtimestamp(1697040000, tz=timezone.utc)
print(dt.isoformat()) # 2023-10-11T00:00:00+00:00
date -u -d @$(echo 1697040000000/1000 | bc)
UPDATE events SET ts_epoch = EXTRACT(EPOCH FROM (ts AT TIME ZONE 'UTC'));
CREATE INDEX idx_events_ts_epoch ON events (ts_epoch);
| Environment | Input Unit | Convert From Epoch (to ISO 8601 UTC) | Convert To Epoch | Notes |
|---|---|---|---|---|
| JavaScript | seconds | new Date(s*1000).toISOString() | Math.floor(new Date(iso).getTime()/1000) | Date uses ms internally |
| JavaScript | millis | new Date(ms).toISOString() | new Date(iso).getTime() | Returns ms as number |
| Python | seconds | datetime.fromtimestamp(s, tz=UTC).isoformat() | int(dt.astimezone(UTC).timestamp()) | Always set tz=UTC |
| Bash (GNU) | seconds | date -u -d @s +%FT%TZ | date -u -d "YYYY-MM-DD HH:MM:SS" +%s | -u for UTC |
| PostgreSQL | seconds | to_timestamp(s) AT TIME ZONE 'UTC' | EXTRACT(EPOCH FROM timestamptz) | timestamptz recommended |
| MySQL | seconds | CONVERT_TZ(FROM_UNIXTIME(s), '+00:00','+00:00') | UNIX_TIMESTAMP('YYYY-MM-DD HH:MM:SS') |
Converting epoch time is simple once you know your units (seconds vs. milliseconds) and your target time zone. Use UTC for storage, ISO 8601 for sharing, and human-friendly formats for display. With the tools and examples above, you can convert epoch time accurately across code, command line, and spreadsheets—without nasty time zone surprises.
Need a fast, accurate conversion right now? Try the ZenixTools Epoch Converter to convert epoch time to readable dates—and back—instantly. Save time, avoid mistakes, and keep your timestamps clean and consistent.
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.
Learn how to convert 1 meter to feet with the exact formula, step-by-step instructions, quick mental math, and real-world examples. Includes charts, best practices, FAQs, and expert tips.
| Force UTC |
| Go | seconds | time.Unix(s,0).UTC().Format(time.RFC3339) | t.Unix() | Use nsec for ms |
| Excel | seconds | =(A2/86400)+DATE(1970,1,1) | INT((A2-DATE(1970,1,1))*86400) | Format as Date |