date +%s prints the current Unix time in seconds. It works the same with GNU date on Linux and BSD date on macOS; converting back is where the two split.
$ date +%s
1792021939
That ran on Debian 13 with GNU coreutils 9.7 at 2026-10-14T23:52:19Z, the instant the tool below starts from; it reads 1792021939 as 2026-10-14 23:52:19 UTC.
Back to a date: GNU vs BSD
# Linux (GNU coreutils)
$ date -u -d @1700000000 +%FT%TZ
2023-11-14T22:13:20Z
$ TZ=America/New_York date -d @1700000000 +'%F %T %Z'
2023-11-14 17:13:20 EST
# macOS (BSD)
$ date -u -r 1700000000 +%FT%TZ
2023-11-14T22:13:20Z
The flags don’t carry over. macOS rejects GNU’s -d with date: illegal option -- d. On GNU, -r names a file whose modification time to print, so date -r 1700000000 fails with date: 1700000000: No such file or directory. On a Mac, Homebrew’s coreutils installs the GNU version as gdate. BusyBox date, the one in Alpine images, accepts -d @1700000000 too.
A date to a timestamp
# GNU
$ date -d '2024-03-10 07:30:00 UTC' +%s
1710055800
# BSD: -j leaves the clock alone, -f gives the input format
$ date -u -j -f '%Y-%m-%d %H:%M:%S' '2024-03-10 07:30:00' +%s
1710055800
Leave out -u, or the UTC in the GNU string, and the time is read in the local zone. With TZ=America/New_York the BSD line prints 1710070200, four hours later, and the tool gives the same 1710070200 for 2024-03-10 07:30:00 in America/New_York.
Gotchas
- Don’t parse the default output. It follows the locale. On the same Debian machine,
LANG=en_US.UTF-8 date -u -d @1700000000printedTue Nov 14 10:13:20 PM UTC 2023andLC_ALL=CprintedTue Nov 14 22:13:20 UTC 2023. Ask for a format instead, like+%FT%TZwith-u. - The zone never changes
%s. A Unix timestamp has no timezone, so-uandTZ=only matter for formatted dates. - Milliseconds: GNU
date +%s%3Nprinted1792021939735in the same run.%Nis a GNU extension that not every BSDdatesupports.
Without starting a process
Bash 5.0 and later set $EPOCHSECONDS and $EPOCHREALTIME, and bash 4.2 added printf '%(%s)T':
$ echo "$EPOCHSECONDS $EPOCHREALTIME"
1792021939 1792021939.753571
$ printf '%(%s)T\n' -1
1792021939
macOS still ships bash 3.2 as /bin/bash, which has neither. Its default shell, zsh, gets both variables from zmodload zsh/datetime.