← All commands
THE COMMAND REFERENCE

date

Print the date and time in a chosen format.

Last updated

Portable / common

Implementation-level reference; examples are not certified for every installed version.

Overview

date prints the current date and time. A format that starts with + chooses the layout, for example +%Y-%m-%d for 2026-11-08. -u uses UTC instead of the local time zone. Giving date a bare number such as 110812002026 tries to set the system clock, so only ever pass it a + format unless you mean to change the time.

The current time changes on every run, so the examples below pipe the result through grep -c, which prints 1 when the output has the expected shape.

Background

A date command appeared in Version 1 Unix, according to the FreeBSD and macOS manuals. Today the name covers GNU date, the date that macOS ships, and the date applet in BusyBox. They agree on printing the current time with a + format, -u, and the conversions the examples use, and differ on how to read or convert a specific time: GNU uses -d, while macOS uses -r and -j -f.

Examples

Print today's date as year-month-day, such as 2026-11-08. The grep checks the shape:

date +%Y-%m-%d | grep -c '^[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}$'

Print the time of day, such as 14:05:09:

date +%H:%M:%S | grep -c '^[0-9][0-9]:[0-9][0-9]:[0-9][0-9]$'

Print the time as seconds since 1970-01-01 UTC, handy for timestamps and comparisons:

date +%s | grep -c '^[0-9]*$'

Print an ISO 8601 timestamp in UTC, such as 2026-11-08T22:05:09Z:

date -u +%Y-%m-%dT%H:%M:%SZ | grep -c 'Z$'

Print the name of the time zone in use; with -u it is always UTC:

date -u +%Z

Options

-u
Use Coordinated Universal Time instead of the local time zone.

Common mistakes

A format without the leading + is read as a new time to set, not as a layout. %Z prints an abbreviation such as PST, which is ambiguous; use %z for a numeric offset when a script needs one. Showing or converting a time given on the command line differs between implementations, so the Common examples only print the current time.

Portability

The Common examples use -u and the %Y %m %d %H %M %S %s %Z conversions, which all three implementations accept. Reading or converting a specific time (-d on GNU, -r and -j -f on macOS) is different on each, and the examples are in the sections below. The Common examples were executed on GNU coreutils 9.11, macOS system tools, and BusyBox 1.37.0 (see the development guide for the exact check).

References

Original explanations, with upstream documentation for further reading. FreeBSD references are comparison material, not a claim of Apple version equivalence.