CURRENT EPOCH · EPOCHTIME.TOOLS · A PRECISION INSTRUMENT FOR TIME
Converter Batch Difference Blog
Languages
JavaScript Python TypeScript Go Rust Java PHP SQL Bash
Specialty
LDAP Timestamp .NET Ticks Chrome/WebKit Cocoa / Core Data Discord Timestamp Excel OADate Unix Hex
Standards
ISO 8601 Guide Year 2038 NTP Timestamp GPS Time Julian Day

Get current Unix timestamp

`date +%s` is universal across Linux, macOS, and other Unix systems.

Seconds (universal)

date +%s
# → 1735689600

Milliseconds (Linux GNU)

date +%s%3N
# → 1735689600123

# or:
date +%s.%3N

Milliseconds (macOS / BSD)

# macOS's BSD date doesn't support %N.
# Use gdate (from coreutils) if available, or:
perl -MTime::HiRes -E 'printf "%d\n", Time::HiRes::time() * 1000'

Nanoseconds (Linux GNU only)

date +%s%N
# → 1735689600123456789

Convert epoch to date

Linux GNU and macOS BSD have different syntax for this.

Linux (GNU coreutils)

date -d @1735689600
# → Wed Jan  1 00:00:00 UTC 2025

# explicit UTC
date -u -d @1735689600

# custom format
date -d @1735689600 +"%Y-%m-%dT%H:%M:%SZ"
# → 2025-01-01T00:00:00Z

macOS (BSD date)

date -r 1735689600
# → Tue Dec 31 19:00:00 EST 2024

# explicit UTC
date -u -r 1735689600

# custom format
date -r 1735689600 "+%Y-%m-%dT%H:%M:%SZ"

Convert date to epoch

Again, different syntax per platform.

Linux (GNU)

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

# from a variable
input="2025-06-15 12:00:00"
date -d "$input" +%s

macOS (BSD)

date -j -u -f "%Y-%m-%d %H:%M:%S" "2025-01-01 00:00:00" +%s
# → 1735689600

# the format string (-f) must match the input exactly

Portable: use Perl

perl -MDate::Parse -E 'say str2time("2025-01-01")'
# → 1735689600

Working with timezones

Set TZ environment variable to convert into a different timezone.

Print in a specific timezone (universal)

TZ="America/New_York" date -d @1735689600
# → Tue Dec 31 19:00:00 EST 2024

# macOS
TZ="America/New_York" date -r 1735689600

List available timezones (Linux)

# IANA timezone database is usually at /usr/share/zoneinfo
ls /usr/share/zoneinfo

# or:
timedatectl list-timezones  # systemd systems

Useful one-liners

Common command-line patterns developers actually need.

Time elapsed since epoch X

epoch_then=1700000000
seconds_ago=$(( $(date +%s) - epoch_then ))
echo "$seconds_ago seconds ago"

Epoch one hour from now

date -d "+1 hour" +%s     # GNU
date -v +1H +%s          # BSD/macOS

Convert log timestamps in a file

# log file has epoch seconds in column 1, replace with human-readable:
awk '{ "date -d @"$1" +%Y-%m-%dT%H:%M:%SZ" | getline d; $1=d; print }' logfile.txt

Check Y2038 limit

echo 2147483647 | xargs -I{} date -d "@{}" -u
# → Tue Jan 19 03:14:07 UTC 2038

Common gotchas

Bash date pitfalls and platform differences.

Linux GNU vs macOS BSD

# These tools have totally incompatible flags:
#   Linux GNU date: -d for input parsing, @ for epoch
#   macOS BSD date: -r for epoch input, -j -f for parsing
# For portable scripts, install GNU coreutils on macOS (brew install coreutils)
# and use 'gdate' instead of 'date'.

@ prefix is GNU only

# date -d @1735689600  works on Linux
# date -d @1735689600  FAILS on macOS
# Use the platform-specific syntax above instead.

Locale affects output

# date's default format respects LC_TIME.
# For predictable output in scripts, explicitly specify a format:
date -d @1735689600 +%s  # always digits
date -d @1735689600       # locale-dependent text

Use the converter

Need to quickly check what a specific timestamp converts to? Use the main converter — paste any value and get every format back.

Working with many timestamps at once? Try the batch converter — paste a list, get a CSV or JSON file back.