Formatting Date and Time with the Unix date Command

How the Unix date command formats dates and times, what format strings change, how locale and time zone affect output, and which formats stay readable and portable.

The Unix date command turns a moment in time into text. That makes it a text transformation: the underlying instant stays the same, while the written form changes with the format string, the locale and the time zone. This review explains what each of those controls does, which formats carry their meaning reliably once copied into logs, filenames, messages or documents, and where the output can mislead a reader or break a script.

Is date formatting suitable for your use?

For most practical jobs, yes, with one condition. You need to choose the output format deliberately instead of relying on the default. The main benefit is precise, repeatable control over how a timestamp is written. The decisive tradeoff is that the more human-friendly the output becomes, with month names, weekday names, 12-hour clocks and zone abbreviations, the more it depends on locale settings and the more ambiguous it can be to other people and programs.

  • A bounded recommendation:
  • For logs, filenames, data exchange and anything a program will parse or sort, use a numeric ISO 8601 style format with an explicit UTC offset, or UTC itself.
  • For messages read by people in one known region, a locale-aware or spelled-out format is fine, as long as the time zone is stated.
  • For calculations and comparisons, store Unix epoch seconds and format them only for display.
  • Avoid the default output and locale-dependent shortcuts such as %c and %x anywhere the text must be machine-readable or must look the same on every system.

What the date command actually changes

date does not alter stored data or the system clock when it formats output. The system clock is only changed if you explicitly set it with administrative rights. For formatting, date reads a point in time, converts it to calendar fields for a given time zone, and writes those fields as characters according to a template that begins with a plus sign. Everything in the template that is not a conversion specifier is printed literally.

date +%Y-%m-%d          # year-month-day, e.g. 2026-10-31
date +%H:%M:%S          # 24-hour time, e.g. 14:05:09
date -u +%Y-%m-%dT%H:%M:%SZ   # UTC timestamp in ISO 8601 form

The example values in the comments show the shape of the output, not a recorded run. Three separate inputs shape the result. Mixing them up causes most formatting mistakes.

Control | What it changes | What it does not change
Format string (+...) | Which fields appear, their order, padding and separators | The instant being described
Time zone (TZ variable, -u) | The clock reading and offset shown for that instant | The instant itself; only its local representation shifts
Locale (LC_TIME, LC_ALL, LANG) | Month and weekday names, AM/PM markers, the layout behind %c, %x and %X | Numeric specifiers such as %Y, %m, %d, %H

Commonly used specifiers

Specifier | Meaning | Locale-dependent?
%Y | Four-digit year | No
%m | Month, 01–12 | No
%d | Day of month, 01–31 | No
%H | Hour, 00–23 | No
%I | Hour, 01–12 | No
%M | Minute, 00–59 | No
%S | Second, 00–60 (60 allows for a leap second) | No
%p | AM/PM marker | Yes
%a / %A | Abbreviated / full weekday name | Yes
%b / %B | Abbreviated / full month name | Yes
%F | Same as %Y-%m-%d | No
%T | Same as %H:%M:%S | No
%z | Numeric UTC offset, e.g. -0400 | No
%Z | Time zone abbreviation, e.g. EDT | Depends on the zone database
%s | Seconds since the Unix epoch | No
%c / %x / %X | Locale's preferred date-and-time / date / time layout | Yes

Clock notation: 12-hour versus 24-hour

US readers often expect a 12-hour clock with AM or PM. date +%I:%M %p produces that, but %p is locale-dependent. Under some locales it may be empty or translated. The 24-hour %H:%M form never needs a marker and cannot be misread between morning and evening. That makes it the safer choice whenever the text may travel beyond its first audience.

GNU and BSD versions differ

Linux distributions usually ship GNU coreutils date. macOS and the BSDs ship a different implementation. The core specifiers listed above are widely shared, but options and extensions differ.

  • Formatting a time other than now: GNU uses -d (for example, date -d @1700000000 or date -d 'next friday'). BSD uses -r for epoch seconds and -j -f to parse an input string.
  • ISO and RFC shortcuts: GNU offers -I / --iso-8601, --rfc-3339 and -R. These are not available in BSD date in the same form.
  • Padding flags such as %-d (no leading zero) and %_d (space padding), and %N for nanoseconds, are GNU extensions. Do not assume they work elsewhere.
  • -u (UTC) is part of the POSIX date specification and works in both families.
# GNU date
date -d @1700000000 +%F

# BSD / macOS date
date -r 1700000000 +%F

Will the output stay readable and usable after copying or sharing?

date writes ordinary characters, so the result copies and pastes like any other text. There is no hidden styling or special glyph substitution. The usability risks come from meaning, not from encoding.

Ambiguity in numeric dates

A form like %m/%d/%y, which yields something like 10/31/26, reads naturally in the US but is read day-first in many other regions. For dates up to the 12th it is genuinely ambiguous. A two-digit year adds a second source of doubt. Year-first numeric dates (%F) avoid both problems and are widely recognized internationally.

Time zone abbreviations

%Z prints abbreviations such as EST or CST. These are convenient for local readers but not unique worldwide; CST, for example, is used for more than one zone. When the exact moment matters, include the numeric offset with %z, or format in UTC with -u and mark it with a trailing Z.

Locale-dependent text

Month names, weekday names, AM/PM markers and the layouts behind %c and %x change with LC_TIME. Under a non-English locale they may contain non-ASCII characters. The same script can therefore produce different text on different machines, which breaks parsing and sorting. Setting the locale for a single command makes output predictable:

LC_ALL=C date +'%a, %d %b %Y %H:%M:%S %z'
TZ=America/New_York date +'%F %H:%M %Z'

Which named locales and time zones are available depends on the system. locale -a lists installed locales. Zone names come from the system's time zone database.

Sorting, searching and filenames

  • Year-first, zero-padded numeric formats sort correctly as plain text; month-name and US-style formats do not.
  • Colons are awkward or disallowed in filenames on some file systems; a form such as %Y%m%d-%H%M%S avoids them.
  • Searching logs is easier when every entry uses one fixed format and one time zone.

Accessibility

Because the output is plain text, assistive technology receives the same characters a sighted reader sees. How a particular screen reader announces a compact numeric date, an abbreviation like EDT or a format such as 2026-10-31T14:05:09Z was not tested for this review, and announcements are known to vary by tool and settings. Where a date is shown to a broad audience, a spelled-out form such as October 31, 2026, 2:05 PM EDT is generally easier to understand by ear and by eye. A machine-readable version can be kept alongside it where needed.

When to keep a plain, standard form

Decorative or highly localized date text is best treated as a display layer. Keep a canonical value as well, either epoch seconds or an ISO 8601 timestamp with offset, whenever the date will be stored, compared, parsed by another program, or shared across regions. Generate the human-friendly version from that value at the point of display.

Gaps and limits of this review

This overview relies on the documented behavior of the date command and strftime-style specifiers. It does not report measurements, version-by-version testing of specific operating systems, or tests with named destinations or assistive technologies. Extension support, especially padding flags, %N and the parsing options, should be confirmed against the man page of the date implementation you actually use.