Learn what epoch mili means, why it matters, and how to convert milliseconds since 1970 across languages. Includes examples, best practices, FAQs, and tools.
If you work with logs, APIs, or databases, you’ve seen timestamps like 1698796800000. That number is epoch mili: time measured in milliseconds since January 1, 1970 (UTC). This guide explains what it means, why it matters, and how to convert it cleanly across languages and systems—without time zone pitfalls.
Epoch mili is a Unix timestamp expressed in milliseconds since January 1, 1970, 00:00:00 UTC. To convert epoch mili to a date, divide by 1000 to get seconds if needed and format in UTC or a target time zone. For example, in JavaScript: new Date(1698796800000). Use epoch mili for precise event timing, sorting, and cross-system consistency.
Epoch mili represents time in milliseconds since the Unix epoch (January 1, 1970 UTC). It’s common in logging, analytics, APIs, and databases because it’s numeric, sortable, and time zone–neutral. Convert with built-in functions (for example, JavaScript Date, Python datetime) and always confirm whether your system expects seconds or milliseconds. Store UTC internally, use ISO 8601 for APIs, and apply local time zones only for presentation.
Epoch mili is a Unix timestamp measured in milliseconds since the Unix epoch: 1970-01-01T00:00:00Z. One second equals 1,000 milliseconds, so epoch in seconds (commonly 10 digits) becomes epoch mili by multiplying by 1,000 (commonly 13 digits).
Notes:
Related terms (used naturally throughout): epoch time, Unix timestamp, milliseconds since 1970, POSIX time, UTC time, epoch ms, timestamp converter, ISO 8601, RFC 3339.
Follow these steps to convert epoch mili to human-readable time and back.
Examples:
JavaScript
// From epoch mili to Date
const ms = 1698796800000;
const date = new Date(ms); // Local time object
const iso = new Date(ms).toISOString(); // UTC ISO 8601 string
// From Date to epoch mili
const nowMs = Date.now(); // milliseconds since 1970
const fromDateMs = new Date().getTime();
Node.js (with timezone formatting via Intl)
const ms = 1698796800000;
const fmt = new Intl.DateTimeFormat('en-US', { timeZone: 'UTC', dateStyle: 'full', timeStyle: 'long' });
console.log(fmt.format(new Date(ms)));
Python
from datetime import datetime, timezone
ms = 1698796800000
# Epoch mili to datetime (UTC)
dt_utc = datetime.fromtimestamp(ms / 1000, tz=timezone.utc)
iso = dt_utc.isoformat() # 'YYYY-MM-DDTHH:MM:SS.mmm+00:00'
# Datetime to epoch mili (UTC)
now_ms = int(datetime.now(tz=timezone.utc).timestamp() * 1000)
Java
import java.time.*;
long ms = 1698796800000L;
Instant instant = Instant.ofEpochMilli(ms);
ZonedDateTime utc = instant.atZone(ZoneId.of("UTC"));
String iso = utc.toOffsetDateTime().toString();
long nowMs = Instant.now().toEpochMilli();
SQL (PostgreSQL)
-- Epoch mili to timestamp (UTC)
SELECT to_timestamp(1698796800000 / 1000.0) AT TIME ZONE 'UTC';
-- timestamp to epoch mili
SELECT (extract(epoch FROM now()) * 1000)::bigint AS epoch_mili_now;
MySQL
-- Epoch mili to datetime (UTC display)
SELECT FROM_UNIXTIME(1698796800000 / 1000);
-- datetime to epoch mili
SELECT FLOOR(UNIX_TIMESTAMP(CURRENT_TIMESTAMP(3)) * 1000) AS epoch_mili_now;
Go
package main
import (
"fmt"
"time"
)
func main() {
ms := int64(1698796800000)
t := time.Unix(0, ms*int64(time.Millisecond)) // UTC
fmt.Println(t.UTC().Format(time.RFC3339Nano))
nowMs := time.Now().UnixNano() / int64(time.Millisecond)
fmt.Println(nowMs)
}
Bash (GNU date)
# Epoch mili to human-readable (UTC)
date -u -d @$(echo "1698796800000/1000" | bc)
# Now to epoch mili (Linux)
python3 - <<'PY'
import time
print(int(time.time()*1000))
PY
JavaScript example
const ms = 1698796800000;
const ny = new Intl.DateTimeFormat('en-US', { timeZone: 'America/New_York', dateStyle: 'medium', timeStyle: 'short' }).format(new Date(ms));
Math.floor(ms / 1000).nowMs + durationMs.Example: Calculate a 7-day retention window in JavaScript
const DAY = 24 * 60 * 60 * 1000;
const cutoff = Date.now() - 7 * DAY; // keep events with timestamp >= cutoff
Example: Partition data by day in SQL (PostgreSQL)
-- Extract the UTC date from epoch mili for partition routing
SELECT (to_timestamp(ts_ms/1000.0) AT TIME ZONE 'UTC')::date AS utc_day
FROM events;
timestamptz for human queries and a mirror BIGINT for pipelines.| Unit | Symbol | Multiplier vs Second | Typical Digits | Precision | Example |
|---|---|---|---|---|---|
| Seconds | s | 1 | 10 | 1 second | 1698796800 |
| Milliseconds | ms | 1,000 | 13 | 0.001 second | 1698796800000 |
| Microseconds | μs | 1,000,000 | 16 | 0.000001 sec | 1698796800000000 |
| Nanoseconds | ns | 1,000,000,000 | 19 | 1e-9 second | 1698796800000000000 |
| Language | Get Now (ms) | From ms to Date/Time | From Date/Time to ms |
|---|---|---|---|
| JavaScript | Date.now() | new Date(ms) | date.getTime() |
| Python | time.time()*1000 or datetime.now(tz=UTC).timestamp()*1000 | datetime.fromtimestamp(ms/1000, tz=UTC) | int(dt.timestamp()*1000) |
| Java | Instant.now().toEpochMilli() | Instant.ofEpochMilli(ms) | instant.toEpochMilli() |
| Go | time.Now().UnixMilli() | time.Unix(0, ms*time.Millisecond) | t.UnixMilli() |
| PostgreSQL | extract(epoch from now())*1000 | to_timestamp(ms/1000.0) | extract(epoch from ts)*1000 |
| MySQL | UNIX_TIMESTAMP(CURRENT_TIMESTAMP(3))*1000 | FROM_UNIXTIME(ms/1000) | UNIX_TIMESTAMP(ts)*1000 |
new Date(ms) or new Date(ms).toISOString() for UTC.int(datetime.now(timezone.utc).timestamp() * 1000).time.Now().UnixMilli() (Go 1.17+), or time.Now().UnixNano()/1e6.Epoch mili is a precise, portable way to represent time in milliseconds since 1970-01-01 UTC. Use it for ordering, analytics, and storage, then convert to human-readable formats for users. By handling units, time zones, and types with care, you can make epoch mili the backbone of reliable, scalable time workflows.
Ready to work faster with time? Try ZenixTools to convert epoch mili to readable dates, generate ISO 8601 strings, and debug time zone issues. Build cleaner pipelines with confidence.
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.