Blog
Custom Print on Demand Apparel — Free Storefront for Your Business
Wild & Free Tools

Epoch Converter on Linux — Bash Commands for Unix Timestamps

Last updated: January 13, 20266 min read Developer Tools

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.

Essential Commands

Get Current Timestamp

date +%s1712345678

Milliseconds: date +%s%3N1712345678123

Epoch to Date

date -d @1712345678Fri 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 to Epoch

date -d "2026-04-06 14:30:00" +%s1775574600

date -d "next Friday" +%s → timestamp for next Friday

date -d "2 hours ago" +%s → timestamp from 2 hours ago

Quick Reference

TaskLinux (GNU)macOS (BSD)
Current epochdate +%sdate +%s
Epoch to datedate -d @1712345678date -r 1712345678
Date to epochdate -d "2026-04-06" +%sdate -j -f "%Y-%m-%d" "2026-04-06" +%s
UTC outputdate -u -d @1712345678date -u -r 1712345678
Custom formatdate -d @N +"%Y-%m-%d"date -r N +"%Y-%m-%d"

The macOS Gotcha

macOS ships with BSD date, not GNU date. The -d @ syntax does not work. Use -r instead:

Install GNU coreutils via Homebrew (brew install coreutils) to get gdate which uses Linux syntax.

Scripting Patterns

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"

When the Terminal Is Overkill

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.

Andrew Walsh
Andrew Walsh Developer Tools & API Writer

Andrew worked as a developer advocate at two SaaS startups writing API documentation used by thousands of engineers. He brings technical precision to his coverage of developer tools and data format converters.

More articles by Andrew →
Launch Your Own Clothing Brand — No Inventory, No Risk