Learn how to convert epoch (Unix time) to readable dates across UTC and time zones. Step-by-step methods, code examples, best practices, and common pitfalls.
If you work with logs, APIs, databases, or analytics, you’ll often need to convert epoch into a human-readable date. Epoch (Unix time) is the count of seconds or milliseconds since 1970-01-01 00:00:00 UTC. This guide shows you exactly how to convert epoch values in tools and code, avoid common mistakes, and format results correctly.
To convert epoch to a date: treat the value as seconds since 1970-01-01 UTC (or divide by 1,000 if it’s milliseconds), then format in your desired time zone. Examples: JavaScript: new Date(SECONDS*1000).toISOString(); Python: datetime.utcfromtimestamp(SECONDS).isoformat() + 'Z'; Linux: date -u -d @SECONDS. Always confirm if your timestamp is in seconds or milliseconds.
Epoch (Unix time) counts seconds from 1970-01-01 UTC. To convert it, first check if the value is in seconds or milliseconds. If it’s milliseconds, divide by 1,000 before converting. Use built-in tools or languages: JavaScript new Date(), Python datetime, Linux date, Excel DATEVALUE/TIME with an offset. Output dates in UTC (ISO 8601) or local time. Watch for time zones, daylight saving, leap seconds, and integer overflow. Prefer UTC storage and ISO 8601 formatting.
Converting epoch means translating a numeric timestamp into a human-readable date and time. Epoch is also called Unix time, POSIX time, or Unix timestamp.
Key facts:
When you convert epoch, you choose:
This section shows how to convert epoch with both tools and code. We’ll cover JavaScript, Python, Excel/Sheets, Linux, PowerShell, SQL, Java, PHP, and Go.
Tip: Milliseconds to seconds: ms / 1000.
Seconds:
const seconds = 1700000000;
console.log(new Date(seconds * 1000).toISOString()); // UTC ISO 8601
Milliseconds:
const ms = 1700000000000;
console.log(new Date(ms).toISOString());
Local time string:
new Date(seconds * 1000).toLocaleString('en-US', { timeZone: 'America/New_York' });
from datetime import datetime, timezone
seconds = 1700000000
print(datetime.fromtimestamp(seconds, tz=timezone.utc).isoformat()) # UTC ISO
ms = 1700000000000
print(datetime.fromtimestamp(ms/1000, tz=timezone.utc).isoformat())
Time zone with zoneinfo (Python 3.9+):
from datetime import datetime
from zoneinfo import ZoneInfo
print(datetime.fromtimestamp(1700000000, tz=ZoneInfo('America/New_York')))
Assume A1 has seconds since epoch.
Excel (UTC):
=(A1/86400)+DATE(1970,1,1)For milliseconds: =((A1/1000)/86400)+DATE(1970,1,1)
Note: Excel shows local time by default. To view UTC, adjust with your offset or use Power Query/Office Scripts. In Google Sheets, use similar formulas; =TEXT(..., "yyyy-mm-ddThh:MM:ss") for formatting.
UTC with seconds:
date -u -d @1700000000 # GNU date
macOS (BSD date) uses milliseconds differently; for seconds:
date -u -r 1700000000
$sec = 1700000000
[DateTimeOffset]::FromUnixTimeSeconds($sec).UtcDateTime.ToString("o")
$ms = 1700000000000
[DateTimeOffset]::FromUnixTimeMilliseconds($ms).UtcDateTime.ToString("o")
-- seconds
date_trunc('second', to_timestamp(1700000000)) AT TIME ZONE 'UTC';
-- milliseconds
(date_trunc('millisecond', to_timestamp(1700000000 / 1000.0))) AT TIME ZONE 'UTC';
Time zone conversion:
to_timestamp(1700000000) AT TIME ZONE 'America/New_York';
-- seconds
FROM_UNIXTIME(1700000000); -- returns local time (server TZ)
-- For UTC explicitly
CONVERT_TZ(FROM_UNIXTIME(1700000000), @@session.time_zone, '+00:00');
-- seconds since epoch to UTC datetime2
SELECT DATEADD(SECOND, 1700000000, '1970-01-01T00:00:00Z');
import java.time.*;
long sec = 1700000000L;
Instant instant = Instant.ofEpochSecond(sec);
System.out.println(instant); // UTC ISO
ZonedDateTime ny = instant.atZone(ZoneId.of("America/New_York"));
System.out.println(ny);
$sec = 1700000000;
echo gmdate('c', $sec); // UTC ISO 8601
package main
import (
"fmt"
"time"
)
func main() {
sec := int64(1700000000)
t := time.Unix(sec, 0).UTC()
fmt.Println(t.Format(time.RFC3339))
}
A product team stores events as milliseconds. To show daily active users in UTC:
/1000A CSV has a column like 1699999999. Excel treats it as a number. Apply:
=(A2/86400)+DATE(1970,1,1)yyyy-mm-dd hh:mm:ssStore send-time in epoch UTC. On the client, convert to local time for display. On the server, always schedule jobs by UTC to avoid DST pitfalls.
Confusing seconds and milliseconds
Ignoring time zones
Daylight Saving Time (DST) errors
Formatting inconsistencies
Z for UTC.32-bit overflow (Year 2038 problem)
Client vs. server clock drift
Truncation vs. rounding
| Method | Online/Offline | Precision | Time Zone Support | Best For |
|---|---|---|---|---|
| ZenixTools Epoch Converter | Online | Seconds/Milliseconds | UTC + Named Zones | Quick checks, sharing |
| JavaScript Date | Offline | ms | Local + IANA (Intl APIs) | Web apps, Node scripts |
| Python datetime | Offline | s/ms (float) | With zoneinfo/pytz | Data pipelines, ETL |
Linux date | Offline | s | UTC and local | Servers, shell scripts |
| Excel/Sheets | Offline/Online | s/ms (via math) | Local (default) | Business users, CSVs |
| PostgreSQL | Offline | s/ms (float) | Named zones | Analytics, SQL transforms |
| Unit | Typical Length | Example | Pros | Cons |
|---|---|---|---|---|
| Seconds | 10 digits | 1700000000 | Compact, widely supported | Loses sub-second precision |
| Milliseconds | 13 digits | 1700000000000 | Higher precision | Easy to confuse with seconds |
new Date(sec*1000).toISOString(), Python datetime.utcfromtimestamp(sec), Linux date -u -d @sec.toLocaleString('en-US', { timeZone: 'America/New_York' }).2023-11-14T22:13:20Z. It’s unambiguous and widely supported.America/Los_Angeles) so the library handles DST rules.=(A1/86400)+DATE(1970,1,1) for seconds, then format the cell as a date/time.datetime.fromtimestamp(ms/1000, tz=timezone.utc).datetime.timestamp(), JS Date.getTime()/1000, Linux date -d '...' +%s.When you need to convert epoch, start by confirming the unit, then choose UTC or a specific time zone, and format with ISO 8601. Use built-in functions to avoid errors and keep your pipeline consistent. With these steps and best practices, you’ll convert epoch values quickly and accurately across any stack.
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.