Live epoch timestamp right now

Format Typical Source
Seconds Most back-end systems, Python, PHP, Go
Milliseconds JavaScript, Java, .NET
Microseconds PostgreSQL, some financial systems
Nanoseconds Go time.Now().UnixNano(), modern Linux

Unix time counts the seconds elapsed since the epoch. That definition is fixed. But the digit count you encounter varies by programming language, and misreading it is the fastest route to a corrupted date.

How to convert epoch to a human-readable date

In JavaScript

javascript const timestamp = 1696156800; // example seconds value const date = new Date(timestamp * 1000); // multiply by 1000 for milliseconds console.log(date.toISOString());

Critical: JavaScript's Date object works in milliseconds. If your timestamp is in seconds, multiply by 1000 first. Forget this and your date lands in 1970.

In Python

```python from datetime import datetime, timezone

timestamp = 1696156800 print(datetime.fromtimestamp(timestamp, tz=timezone.utc)) ```

In the Shell

bash date -u -d @1696156800

How to convert a date back to epoch

JavaScript

javascript const date = new Date("2023-10-01T12:00:00Z"); const epochSeconds = Math.floor(date.getTime() / 1000);

Python

```python from datetime import datetime, timezone

dt = datetime(2023, 10, 1, 12, 0, 0, tzinfo=timezone.utc) print(int(dt.timestamp())) ```

The one-line rule

Always convert to UTC first. If your date string has no timezone indicator, assume UTC, never local time. This is the single most common source of epoch conversion bugs.

Common epoch formats: seconds, milliseconds, microseconds

Unit Typical Source
Seconds Unix/Linux date +%s, Python, PHP
Milliseconds JavaScript Date.now(), Java System.currentTimeMillis()
Microseconds PostgreSQL EXTRACT(EPOCH FROM now())
Nanoseconds Go time.Now().UnixNano(), Linux date +%s%N

How to tell what you have: Count the digits.

  • 10 digits = seconds
  • 13 digits = milliseconds
  • 16 digits = microseconds
  • 19 digits = nanoseconds

Negative timestamps are valid for dates before 1970. A value of -86400 is 31 December 1969 00:00:00 UTC. Do not reject them, and your parser should not either.

Why epoch appears in APIs and logs

Epoch time is:

  • Timezone-agnostic. It is always UTC by definition. No AM/PM confusion, no offset math.
  • Sortable. Larger numbers are always later. No string comparison gotchas.
  • Compact. Ten digits instead of twenty-four characters.
  • Comparable. Subtract two timestamps and get exact elapsed seconds.

When to use what

Scenario Best Format
API responses ISO 8601 with Z suffix
Database primary keys Big integer seconds or milliseconds
Log files Epoch seconds (compact) or ISO 8601 (readable)
JavaScript timestamps Milliseconds, because that is what Date expects natively