Convert an Epoch Timestamp in the Terminal
On macOS use date -u -r 1700000000 to turn a timestamp into a date. On Linux use date -u -d @1700000000. The -u flag keeps the output in UTC. Add a fractional part on GNU date to keep milliseconds. To get a timestamp back, run date -u +%s.
By Michael Lip · Updated 2026-10-28
Two versions of date are in common use. BSD date ships with macOS. GNU date ships with Linux and is often installed on macOS as gdate. The flags differ, so a command copied from the wrong page fails with an illegal option error.
macOS and BSD: date -r
date -u -r 1700000000 '+%Y-%m-%dT%H:%M:%SZ'
Output on this machine:
2023-11-14T22:13:20Z
-r takes seconds since the epoch. -u prints UTC. Without -u the same instant prints in the local zone.
Linux and GNU: date -d @
date -u -d @1700000000 '+%Y-%m-%dT%H:%M:%SZ'
Output from GNU date on this machine, installed as gdate:
gdate -u -d @1700000000 '+%Y-%m-%dT%H:%M:%SZ'
2023-11-14T22:13:20Z
The at sign is part of the GNU syntax. A bare number is read as another date format and gives a wrong or failed result.
Millisecond timestamps
gdate -u -d @1700000000.123 '+%Y-%m-%dT%H:%M:%S.%3NZ'
2023-11-14T22:13:20.123Z
GNU date accepts a fractional part after the at sign. BSD date on macOS does not. Divide by 1000 first when no GNU date is installed: date -u -r $((1700000000123/1000)).
The reverse direction
date -u +%s
gdate -u +%s
Both printed the same value on this machine at the same moment: 1793176000. Use +%s to stamp a log line or to compare two files.
Before 1970
gdate -u -d @-86400 '+%Y-%m-%dT%H:%M:%SZ'
date -u -r 0 '+%Y-%m-%dT%H:%M:%SZ'
1969-12-31T00:00:00Z
1970-01-01T00:00:00Z
A negative timestamp is valid. date -r 0 shows the start of the epoch itself, which is a quick sanity check on any machine.
Which timestamp is in the file
Count the digits. Ten digits is seconds. Thirteen digits is milliseconds. Nineteen digits is nanoseconds, and both versions need a division before the conversion. For a browser check of one value, the epoch to date converter shows UTC and your local time side by side, and the precision guide covers the nanosecond case.
Frequently Asked Questions
How do I convert a Unix timestamp to a date in the terminal?
Use date -u -r TIMESTAMP on macOS and date -u -d @TIMESTAMP on Linux.
Why does date -d fail on macOS?
The macOS date is the BSD version and has no -d flag. Install GNU date as gdate or use date -r.
How do I get the current Unix timestamp in bash?
Run date -u +%s. The value is in seconds.