Bash

Epoch ↔ Human Date Conversion

admin by @admin ADMIN
1d ago
May 31, 2026
Public
0 0 up · 0 down Sign in to vote
`date +%s` gives now-as-epoch; `date -d @N` converts an epoch number back to a human date. Often what API responses expect / return.
Bash
Raw
# Current epoch
date +%s                               # 1735689600

# Epoch to human (UTC)
date -u -d @1735689600 +"%F %T UTC"    # 2025-01-01 00:00:00 UTC

# Epoch to human (local TZ)
date -d @1735689600                    # Tue Dec 31 18:00:00 CST 2024

# Human → epoch
date -d "2025-01-01 00:00:00 UTC" +%s  # 1735689600

# Epoch in milliseconds (for JS timestamps)
echo $(( $(date +%s) * 1000 ))         # 1735689600000

# Or with nanosecond precision
date +%s%N | cut -c1-13                # epoch ms via slice
Tags

Save your own code snippets

Create a free account and build your private vault. Share publicly whenever you want.