Linux has built-in epoch conversion. The date command handles everything. Here are the commands you need, plus the macOS differences that trip everyone up.
date +%s → 1712345678
Milliseconds: date +%s%3N → 1712345678123
date -d @1712345678 → Fri Apr 5 18:14:38 UTC 2024
Custom format: date -d @1712345678 +"%Y-%m-%d %H:%M:%S" → 2024-04-05 18:14:38
date -d "2026-04-06 14:30:00" +%s → 1775574600
date -d "next Friday" +%s → timestamp for next Friday
date -d "2 hours ago" +%s → timestamp from 2 hours ago
| Task | Linux (GNU) | macOS (BSD) |
|---|---|---|
| Current epoch | date +%s | date +%s |
| Epoch to date | date -d @1712345678 | date -r 1712345678 |
| Date to epoch | date -d "2026-04-06" +%s | date -j -f "%Y-%m-%d" "2026-04-06" +%s |
| UTC output | date -u -d @1712345678 | date -u -r 1712345678 |
| Custom format | date -d @N +"%Y-%m-%d" | date -r N +"%Y-%m-%d" |
macOS ships with BSD date, not GNU date. The -d @ syntax does not work. Use -r instead:
date -d @1712345678date -r 1712345678Install GNU coreutils via Homebrew (brew install coreutils) to get gdate which uses Linux syntax.
Check if a timestamp has expired:
NOW=$(date +%s) EXPIRY=1775944800 if [ "$NOW" -gt "$EXPIRY" ]; then echo "Expired" else echo "Still valid" fi
Calculate elapsed time:
START=$(date +%s) # ... do work ... END=$(date +%s) echo "Took $((END - START)) seconds"
If you are reading docs, debugging an API response, or checking a JWT claim and just need to convert one timestamp quickly, the browser-based converter is faster than remembering whether it is -d @ or -r.
Quick conversion without remembering syntax.
Convert Instantly →Related: Cron Generator, Regex Tester, JSON Formatter.