Home·Terminal commands

date

Processes and system

Usage

date [+FORMAT]

Prints the current time in any format you like and does date arithmetic; the format after `+` is the same everywhere, but shifting a date is `-d` on GNU and `-v` or `-j -f` on macOS/BSD.

Common flags

FlagMeaning
+%FShorthand for %Y-%m-%d.
+%sUnix epoch seconds right now.
-uWork in UTC instead of local time.
-d "yesterday"Parse or shift a date. GNU only.
-d @1700000000Turn epoch seconds into a readable date. GNU only.
-v-2dShift by two days on macOS/BSD, which has no -d.
-r 1700000000Read epoch seconds on macOS/BSD.
-j -f "%Y-%m-%d"Parse a string without setting the clock, on macOS/BSD.

Examples

date -u +"%Y-%m-%dT%H:%M:%SZ"

An ISO 8601 timestamp in UTC, the same on both platforms.

date -d "2 days ago" +%F

The date two days back on GNU; on macOS it is date -v-2d +%F.

date +%s

Epoch seconds, for a filename or a quick difference.

What is running and what is eating the machine. Identifying it comes before killing it.

How to read this

  • Square brackets [ ] mark a part you may leave out.
  • An ellipsis … means you can list more than one.
  • Flags are case-sensitive — in some commands -r and -R do different things.

Questions

Q. What does date do?

Prints the current time in any format you like and does date arithmetic; the format after `+` is the same everywhere, but shifting a date is `-d` on GNU and `-v` or `-j -f` on macOS/BSD.

Q. How do I type it?

date [+FORMAT] — square brackets mark the parts you can leave out.

Q. How many flags are worth knowing?

8 are listed here; the full set is in man date. This command sits under Processes and system.

Related commands

man page: man date