A human-friendly guide to epoch time conversion with clear steps, real-world use cases, code in JS/Python/SQL, and expert tips to avoid time zone and millisecond pitfalls.
Epoch time conversion shows the exact moment a timestamp represents by turning raw seconds or milliseconds since 1970-01-01 UTC into a readable date, and back again. If you work with logs, APIs, databases, or IoT data, you’ll see epoch timestamps everywhere. This guide explains the concept in plain language and gives you reliable steps, code, and tips to get it right.
Epoch time conversion translates a Unix timestamp—seconds or milliseconds since 1970-01-01 00:00:00 UTC—into a human-readable date and time, and vice versa. To convert, first confirm if the value is in seconds (10 digits) or milliseconds (13 digits). Then convert using your language’s UTC functions or a tool like ZenixTools. Always account for time zones and daylight saving.
Epoch time (Unix time) counts seconds since 1970-01-01 UTC. Converting it lets you display or store dates consistently across systems. Know whether your timestamp is in seconds or milliseconds, convert in UTC, and only format for local time when displaying to users. This guide provides clear steps, code examples (JavaScript, Python, Java, Bash, SQL), real-world use cases, common pitfalls (time zones, DST, leap seconds, Y2038), and best practices—plus a quick, accurate converter from ZenixTools.
Epoch time (also called Unix time or POSIX time) is a simple integer that represents the number of seconds that have elapsed since the Unix epoch: 1970-01-01 00:00:00 Coordinated Universal Time (UTC), not counting leap seconds. Many systems store timestamps this way because it’s compact, timezone-agnostic, and easy to compare.
Epoch time conversion is the process of translating:
Two common units appear in the wild:
This difference matters. Dividing or multiplying by 1000 at the wrong time can shift your date by decades. Good tools and careful APIs state the unit clearly. In most programming languages, you’ll find both variants supported by standard libraries.
Related terms you’ll see include Unix timestamp, UTC, ISO 8601, RFC 3339, and time zone offsets like +05:30. When you convert, use UTC internally, and only switch to local time for display.
Time is the backbone of logging, analytics, scheduling, and security. Converting epoch time correctly:
If you ship software, manage data, or audit systems, solid epoch handling reduces confusion and avoids bugs that are hard to trace. Mistakes can flip AM/PM, push events to the wrong day, or break SLA calculations. Clear, consistent conversions make your workflows predictable.
Follow these steps to convert epoch values safely and repeatably.
JavaScript (Node.js/Browser):
// Seconds → Date (UTC display)
const epochSec = 1700000000;
const dUtc = new Date(epochSec * 1000);
console.log(dUtc.toISOString()); // 2023-11-14T22:13:20.000Z
// Milliseconds → Date
const epochMs = 1700000000000;
console.log(new Date(epochMs).toISOString());
// Date → Seconds
const seconds = Math.floor(new Date('2023-11-14T22:13:20Z').getTime() / 1000);
Python (datetime):
from datetime import datetime, timezone
# Seconds → ISO 8601 (UTC)
epoch_sec = 1700000000
print(datetime.fromtimestamp(epoch_sec, tz=timezone.utc).isoformat())
# Milliseconds → ISO 8601 (UTC)
epoch_ms = 1700000000000
print(datetime.fromtimestamp(epoch_ms / 1000, tz=timezone.utc).isoformat())
# Date → Seconds
dt = datetime(2023, 11, 14, 22, 13, 20, tzinfo=timezone.utc)
print(int(dt.timestamp()))
Java (java.time):
import java.time.*;
// Seconds → ISO 8601
epochSecond: {
long s = 1700000000L;
Instant i = Instant.ofEpochSecond(s);
System.out.println(i.toString()); // 2023-11-14T22:13:20Z
}
// Milliseconds → ISO 8601
{
long ms = 1700000000000L;
Instant i = Instant.ofEpochMilli(ms);
System.out.println(i.toString());
}
// Date → Seconds
{
ZonedDateTime zdt = ZonedDateTime.parse("2023-11-14T22:13:20Z");
long seconds = zdt.toEpochSecond();
System.out.println(seconds);
}
Bash (coreutils + date):
# Seconds → date (UTC)
date -u -d @1700000000 +"%Y-%m-%dT%H:%M:%SZ"
# Milliseconds → date (UTC): divide by 1000 first
ms=1700000000000; date -u -d @$(($ms/1000)) +"%Y-%m-%dT%H:%M:%SZ"
# Date → seconds
date -u -d "2023-11-14T22:13:20Z" +%s
SQL (PostgreSQL):
-- Seconds → timestamp with time zone (UTC)
SELECT to_timestamp(1700000000) AT TIME ZONE 'UTC';
-- Milliseconds → divide by 1000
SELECT to_timestamp(1700000000000 / 1000.0) AT TIME ZONE 'UTC';
-- Date → seconds since epoch (UTC)
SELECT EXTRACT(EPOCH FROM TIMESTAMPTZ '2023-11-14 22:13:20+00');
| Method / Tool | Best For | Pros | Cons |
|---|---|---|---|
| ZenixTools Online Converter | Quick checks, copy/paste conversions | Fast, accurate, human-friendly, no setup | Requires internet access |
| JavaScript Date (Node/Browser) | Web apps, quick scripts | Built-in, easy ISO 8601 output | Local time pitfalls if not careful |
| Python datetime | Data pipelines, ETL | Clear UTC handling, rich library | Time zone handling needs timezone-aware objects |
| Java java.time | Enterprise apps | Strong typing, precise | More verbose than scripting languages |
| Bash date | CLI one-offs | Ubiquitous on Linux, quick | OS differences (BSD vs GNU) |
| PostgreSQL to_timestamp | Database-side transforms | Efficient in queries, indexing | DB-specific syntax |
What is epoch time? Epoch time is the number of seconds that have passed since 1970-01-01 00:00:00 UTC, ignoring leap seconds. It’s also called Unix time or POSIX time.
Is my timestamp in seconds or milliseconds? Count the digits. Ten digits often indicate seconds (e.g., 1700000000). Thirteen digits often indicate milliseconds (e.g., 1700000000000). Check your API docs to be sure.
How do I convert epoch to a readable date in JavaScript? Multiply seconds by 1000 for milliseconds, create a Date, and use toISOString(): new Date(sec * 1000).toISOString(). For milliseconds: new Date(ms).toISOString().
How do I handle time zones during conversion? Convert and store in UTC. Only at display time, format into the user’s local time zone using reliable libraries or platform functions.
Does epoch time account for leap seconds? No. POSIX time ignores leap seconds. Most systems smear or skip them; results remain monotonic for practical purposes.
What about the Year 2038 problem? 32-bit signed integers overflow around 2038-01-19. Use 64-bit integers (long, bigint) for epoch seconds or milliseconds to be safe.
How do I convert in Python? Use datetime.fromtimestamp(value, tz=timezone.utc) for seconds. For milliseconds, divide by 1000 first. Use isoformat() to get an ISO 8601 string.
How can I convert in SQL? PostgreSQL: to_timestamp(seconds) for seconds; divide milliseconds by 1000. Use EXTRACT(EPOCH FROM ts) to get seconds.
How do I convert local time to epoch? Parse the local time with an explicit time zone or offset, convert it to UTC, then extract epoch seconds or milliseconds.
What’s the difference between ISO 8601 and RFC 3339? RFC 3339 is a profile of ISO 8601 commonly used in internet protocols. An example is 2023-11-14T22:13:20Z.
Why are my conversions off by several hours? Likely a time zone issue. Ensure you convert in UTC first, and apply local time zones only when formatting for display.
Epoch time conversion is straightforward once you know the rules: confirm units, work in UTC, and use standard libraries. Whether you’re correlating logs, storing events, or formatting dates for users, consistent handling prevents costly time bugs. Keep inputs validated, document units clearly, and test edge cases like DST and 2038. When in doubt, verify with ZenixTools and make epoch time conversion a reliable part of your workflow.
Need a quick, accurate check? Paste any timestamp into the free ZenixTools Epoch Converter. Convert seconds or milliseconds to readable dates, switch time zones, and copy ISO 8601 strings in seconds. Save time and avoid mistakes—try it now.
A complete, human-friendly guide to convert to WebP for faster sites and better SEO. Learn benefits, step-by-step workflows, code examples, and expert tips. Use ZenixTools to convert to WebP in seconds.
A practical, expert guide to convert base64 to string across languages, with steps, examples, pitfalls, and best practices.
Can epoch be negative? Yes. Dates before 1970-01-01 UTC yield negative epoch values. Ensure your types support negatives.
How do I convert in Excel or Google Sheets? Excel stores dates as days. Convert epoch seconds with: =((A1/86400) + DATE(1970,1,1)) and format as date/time. Adjust for time zone as needed.
Should I store epoch seconds or milliseconds? Use milliseconds if you need sub-second precision. Otherwise, seconds are fine. Be consistent and document your choice.
How do I check if my result is correct? Cross-check with multiple sources: language library output, a trusted CLI (date), and the ZenixTools converter.