Bash Date Format and Time Zones: UTC, Offsets and Local Clock Notation

How to format dates and times in Bash with date, UTC, numeric offsets and TZ, plus which formats stay unambiguous when copied, shared, parsed or localized.

Formatting a timestamp in Bash looks like a cosmetic choice, but it decides whether the result still identifies one specific moment once it leaves your terminal. This review covers how the date command and the Bash printf builtin render time, how UTC and time zone selection work, and which output formats keep their meaning after copying, sharing or localizing. The guidance is based on documented behavior of GNU coreutils date, BSD/macOS date and Bash itself. No hands-on test results were supplied for this article, so the examples below show commands and output patterns, not captured output.

Short answer: which format suits which use

For logs, file names, data exchange and anything another program will read, use UTC in an ISO 8601 style layout such as year-month-day, a T separator, 24-hour time and a trailing Z. It is unambiguous, sorts correctly as plain text and does not depend on the reader's location or locale. The tradeoff is that people have to convert it to their own clock mentally, which is a real cost in user-facing messages.

When local wall-clock time matters, for example a scheduled event in a specific city, output local time with a numeric UTC offset rather than a zone abbreviation. Reserve abbreviations, 12-hour notation and locale-dependent formats for display to a known human audience, and keep a fixed numeric form alongside them whenever the value might be stored, compared or reused. A fixed, locale-independent format is preferable to localized output in scripts, cron jobs, CSV files, filenames and anywhere output is parsed.

What formatting changes and what it does not

The date command reads the system clock, which counts time as an instant independent of any time zone, and renders that instant as text. The -u option and the TZ environment variable change only how the instant is rendered for that command. They do not change the system clock or the stored time of any file. Setting the clock is a separate operation (date -s in GNU date) that normally requires administrative privileges and should not be confused with formatting.

Formatting can, however, discard information. A format with no zone indicator produces a wall-clock reading that cannot be mapped back to a single instant. A zone abbreviation such as CST is ambiguous because the same letters are used for different regions with different offsets. A 12-hour time without an AM/PM marker is ambiguous across a 12-hour span. Once that information is dropped from the text, nothing in the string can recover it.

Core commands for UTC and local time

# Current time in UTC, ISO 8601 style with a Z suffix (GNU and BSD)
date -u +%Y-%m-%dT%H:%M:%SZ

# Local time with a numeric offset, portable form (+hhmm)
date +%Y-%m-%dT%H:%M:%S%z

# Local time with a colon in the offset (+hh:mm), GNU date only
date +%Y-%m-%dT%H:%M:%S%:z

# GNU shortcuts
date -u --iso-8601=seconds
date --rfc-3339=seconds
date -R

# Seconds since the Unix epoch
date +%s

The Z suffix in the first command is literal text in the format string. It is only correct because -u forces UTC rendering. Writing a literal Z after a local time is a common mistake that silently mislabels the value.

Format specifiers that matter for time zones

Specifier | Output | Notes
%Y-%m-%d | Four-digit year, zero-padded month and day | Sorts correctly as text
%H:%M:%S | 24-hour time | Avoids AM/PM ambiguity
%I and %p | 12-hour hour and AM/PM marker | %p is locale-dependent and can be empty
%z | Numeric offset as +hhmm or -hhmm | Widely supported, unambiguous
%:z | Numeric offset as +hh:mm | GNU date extension, not portable
%::z | Offset as +hh:mm:ss | GNU date extension
%Z | Zone abbreviation | Ambiguous, unsuitable for parsing
%s | Seconds since the epoch | Zone-independent, not human-readable
%c, %x, %X | Locale's preferred date and time layouts | Vary with LC_TIME, avoid in scripts

Choosing a time zone with TZ

Prefixing a command with a TZ assignment renders the time in that zone for that command only. Use region names from the IANA time zone database, such as America/New_York or Europe/Berlin, because these encode daylight saving rules and historical changes. Fixed abbreviations do not.

TZ=America/New_York date +%Y-%m-%dT%H:%M:%S%z
TZ=Asia/Tokyo date +'%Y-%m-%d %H:%M %Z'
TZ=UTC date +%Y-%m-%dT%H:%M:%SZ
  • Two traps are worth knowing before relying on TZ:
  • POSIX-style TZ strings invert the sign: TZ=UTC+3 means three hours behind UTC, and the zone name Etc/GMT+3 likewise means UTC minus three hours. This is the opposite of how offsets appear in %z output.
  • An unrecognized TZ value usually does not produce an error. On common systems it falls back to UTC, so a typo in a zone name can yield plausible but wrong output. Check the %z offset in the result rather than assuming the zone was applied.

GNU date versus BSD and macOS date

The basic +FORMAT syntax and -u work on both families, but many options differ. GNU date parses arbitrary input with -d, accepts an epoch value written as -d @SECONDS, and offers --iso-8601, --rfc-3339 and -R. BSD and macOS date use -r SECONDS to format an epoch value, -j -f INPUT_FORMAT to parse a string without setting the clock, and -v to adjust dates. The colon offset forms such as %:z belong to GNU date and should not be assumed elsewhere. A script that must run on both should either stick to the shared subset (%Y, %m, %d, %H, %M, %S, %z, -u) or detect which date implementation is installed.

# Format a given epoch time in UTC
date -u -d @SECONDS +%Y-%m-%dT%H:%M:%SZ    # GNU
date -u -r SECONDS +%Y-%m-%dT%H:%M:%SZ     # BSD / macOS

Clock notation and locale

Several specifiers follow the LC_TIME locale category: %c, %x, %X, %r, %p, and the month and weekday names from %b, %B, %a and %A. The same command can therefore print different words, orders and clock conventions on different machines. Some locales do not define AM/PM strings, in which case %p can come out empty and a 12-hour time loses its meaning. Month and weekday names can also contain non-ASCII characters in other languages.

For stable output in scripts, either use numeric specifiers only or set the locale explicitly for the command, for example LC_ALL=C date +'%a %d %b %Y %H:%M:%S %z'. For localized display, set LC_TIME to the audience's locale on purpose, prefer 24-hour %H unless the audience expects 12-hour time, and pair %I with %p only after confirming that the target locale defines the marker.

Formatting without calling date: the Bash printf builtin

Since Bash 4.2, the printf builtin accepts a %(FORMAT)T conversion that formats time without starting an external process. An argument of -1 means the current time and an epoch number formats that instant. Passing -1 explicitly avoids differences between Bash versions in what an omitted argument means. This builtin uses the C library's strftime, not GNU date's own formatter, so GNU-only forms such as %:z may not work. Making it render UTC depends on TZ being visible to the shell, and exporting TZ inside a subshell is the more predictable approach. Verify the result on the Bash version you deploy to.

printf '%(%Y-%m-%dT%H:%M:%S%z)T\n' -1
( export TZ=UTC; printf '%(%Y-%m-%dT%H:%M:%SZ)T\n' -1 )

Will the result stay usable after copying or sharing?

Numeric ISO 8601 style output in UTC, or local time with %z, is plain ASCII text. It copies cleanly between terminals, editors and chat tools, can be found reliably with grep, and sorts chronologically as plain text when all values share the same zone and zero-padded layout. Mixed offsets break that sorting property, which is another reason to standardize on UTC for stored data.

Locale-dependent output is less portable. Another person or program may not recognize translated month names, and abbreviations like %Z cannot be reliably converted back to an offset. Values without any zone indicator will be read in the reader's own zone, which may not be yours. When a timestamp is shared with people in other regions, include either UTC with Z or a numeric offset.

Accessibility and destination-specific behavior are not covered by the supplied evidence. No documentation or scoped test was provided on how screen readers announce compact ISO strings, or on how particular spreadsheets, databases or messaging apps reinterpret pasted timestamps. Some applications are known to convert date-like text automatically, so test the specific destination before relying on it. In user interfaces, offering a spelled-out human-readable form next to the machine form is a reasonable precaution for readers who rely on assistive technology.

Evidence gaps

  • No captured command output, version-specific test runs or platform measurements were supplied, so the examples show patterns rather than verified results.
  • Behavior for invalid TZ values and the printf builtin's handling of TZ can vary by system and Bash version and should be checked locally.
  • Screen reader handling of formatted timestamps and automatic conversion in specific destination applications were not tested.

Quick checklist

  • Machine-readable or stored: date -u +%Y-%m-%dT%H:%M:%SZ, or %s for epoch seconds.
  • Local time that must stay unambiguous: include %z, or %:z on GNU date.
  • Specific region: use an IANA zone name in TZ and confirm the offset in the output.
  • Scripts: avoid %c, %x, %X, %p and %Z, or force LC_ALL=C.
  • Human display: localize deliberately and keep a numeric form available wherever the value may be reused.
  • Cross-platform scripts: limit yourself to the shared specifiers or detect GNU versus BSD date.