Jump to content

Timestamp format string

From Wikipedia, the free encyclopedia

A timestamp format string (phrasing may vary) is a string used to specify the text format of a timestamp, for producing output (similar to printf) or parsing input (similar to scanf).

It is primarily composed of specifiers, listed below, depending on the system in use. Characters with no special meaning are generally passed through as-is.

Most programs, such as the Unix date command,[1] use a subset of the specifiers used in C, sometimes with their own extensions.

Specifiers

[edit]
Description Specifier
Unit of time Reference point variant Format C date & time[2][3][4][5][1][6][7] Unicode[8]/ICU[9] PHP[10]
Single elements in the hierarchy of units
Calendar era Full GGGG
Abbreviated G, GG, GGG
Minimal GGGGG
Unspecified %EC (C99)

%N (AIX)

Century %C (C99)
Year Era-independent (continuous numbering) Zero-padded to the specified number of digits u...
Gregorian year %Y
Calendar year of era Unpadded y
Zero-padded to 3 digits yyy
Zero-padded to 4 digits yyyy
Unspecified? %Ey (C99)

%o (AIX)

Of century %y yy y
Gregorian of first day of year Zero-padded to the specified number of digits r...
For ISO week date (containing most of the week) Unpadded Y
Zero-padded to 3 digits YYY
Zero-padded to 4 digits YYYY
Unspecified? %G (C99) o
Of century for ISO week date %g (C99)
Of cycle, name U...
Quarter Of year Single-digit number Q, QQQQQ, q, qqqqq
Two-digit number QQ, qq
"Q" and number QQQ, qqq
Phrase ('nth quarter'), for use as part of a date QQQQ
Phrase ('nth quarter'), for use by itself qqqq
Month Naming Full, for use as part of a date %B MMMM F
Full, for use by itself %OB (C23) LLLL
Abbreviated, for use as part of a date %b (since C89)

%h (C99, legacy[11])

MMM M
Abbreviated, for use by itself %Ob (C23)

%Oh (GNU extension)

LLL
Minimal MMMMM, LLLLL
Zero-based numbering
One-based numbering Unpadded M, L n
Zero-padded %m MM, LL m
Week Of year for ISO week date Unpadded w
Zero-padded %V ww W
Of year, where the first Sunday starts week 1 %U (not GLib)
Of year, where the first Monday starts week 1 %W (not GLib)
Of month W
Instance of weekday in month F
Day Modified Julian day Zero-padded to the specified number of digits g...
Day of year, starting with 0 Unpadded z
Day of year, starting with 1 Unpadded D
Zero-padded to 2 digits DD
Zero-padded %j DDD
Day of month, starting with 1 Unpadded d j
Zero-padded %d[a] dd d
Space-padded %e
Day of week, 0 = Sunday %w w
Day of week, 7 = Sunday %u (C99) N
Day of week, locale-dependent offset Single-digit number e, c, cc
Two-digit number ee
Day of week, by name Full, for use as part of a date %A EEEE, eeee l
Full, for use by itself cccc
Abbreviated (3 letters) %a E, EE, EEE, eee, ccc D
Abbreviated (2 letters) EEEEEE, eeeeee, cccccc
Minimal EEEEE, eeeee, ccccc
Period of day AM/PM Uppercase or unspecified %p A
Lowercase %P (GNU extension) a
Full aaaa
Abbreviated a, aa, aaa
Minimal aaaaa
AM/PM/noon/midnight Full bbbb
Abbreviated b, bb, bbb
Minimal bbbbb
Descriptive Full BBBB
Abbreviated B, BB, BBB
Minimal BBBBB
Hour 24-hour clock, 0–23 Unpadded H G
Zero-padded %H HH H
Space-padded %k (GNU, AIX)
24-hour clock, 1–24 Unpadded k
Zero-padded kk
12-hour clock, 0–11 Unpadded K
Zero-padded KK
12-hour clock, 1–12 Unpadded h g
Zero-padded %I hh h
Space-padded %l (GNU extension)
Minute Of hour Unpadded m
Zero-padded %M mm i
Second Since Unix epoch (Unix time) %s (GNU extension) U
Of minute Unpadded s
Zero-padded %S ss s
Subdivisions of a second Of day Milliseconds A...
Of second Tenths of a second %1N (FreeBSD date) S
Hundredths of a second %2N (FreeBSD date) SS
Milliseconds %3N (FreeBSD date) SSS
Microseconds %f (Python, GLib)

%6N (FreeBSD date)

SSSSSS
Nanoseconds %N (GNU and FreeBSD date)

%9N (FreeBSD date)

SSSSSSSSS v
Automatic precision %-N (FreeBSD date) u
Predefined combinations
Year and era %EY (C99)

%E (AIX)

X, x, Y
Date and time Locale-dependent but with Gregorian year %c
Locale-dependent with local calendar %Ec (C99)
ISO 8601 c
RFC 2822 / RFC 5322 r
Calendar date Locale-dependent but with Gregorian year %x
Locale-dependent with local calendar %Ex (C99)
Month/day/year %D (C99, not GLib)
Year-month-day %F (C99)
Month and day
Hour and period of day Locale-dependent, with AM/PM if 12-hour j...
Locale-dependent, with any allowed period C...
Locale-dependent, without AM/PM J...
Time of day in hours and minutes Hour:minute %R (C99)
Time of day, unspecified precision Locale-dependent %EX (C99)
Time of day, unspecified precision, 12-hour clock Locale-dependent %r (C99)
Time of day, HMS Locale-dependent %X
Hour:minute:second %T (C99)
Specific characters
Whitespace (strptime parses all whitespace for any such specifier) Newline %n (C99)
Horizontal tab %t (C99)
Percent sign %%
Apostrophe / single quote ''
Escaping other metacharacters 'characters' \character
Miscellaneous
Time zone Name or abbreviation Full name with DST specification zzzz
Full name without DST specification vvvv
Abbreviation with DST specification z, zz, zzz T
Abbreviation without DST specification v
Unspecified %Z e
Nominal location Area/Location VV
Place name followed by "Time" VVVV
Place name VVV
Abbreviation V
UTC offset ±Hours:minutes:seconds %::z (gnulib)
±Hours:minutes with "GMT", or "Z", long ZZZZ, OOOO
±Hours:minutes with "GMT", or "Z", short O
±Hours:minutes %:z (gnulib) XXX (uses "Z"), xxx (uses 0) P
±Hours:minutes, or "Z" for 0 p
Colon-separated, automatic length %:::z (gnulib)

%:z (Python)

ZZZZZ, XXXXX (use "Z"), xxxxx (uses 0)
Concatenated number, 4 or 6 digits Z, ZZ, ZZZ, xxxx
Concatenated number, 4 or 6 digits, or "Z" XXXX
Concatenated number, at least 4 digits %z (C99)
Concatenated number, 4 digits xx O
Concatenated number, 4 digits, or "Z" XX
Concatenated number, 2 or 4 digits x
Concatenated number, 2 or 4 digits, or "Z" X
Total number of seconds Z
Is in daylight saving time 1 if daylight time, 0 if standard time I
Is leap year 1 if leap year, 0 if not L
Number of days in month t
Ordinal suffix for day of month S
Swatch Internet Time Zero-padded B
Modifiers
Number formatting Numbering system Arabic numerals (default)
Locale-specific %O... (C99?)
Padding if too short Zeroes %0... (GNU extension)
Spaces (e.g. figure space) %_... (GNU extension)
None (unpadded) %-... (GNU extension)
Letter formatting Letter case Opposite %#... (gnulib)
Uppercase %^... (gnulib)
Field width Decimal number after flags Often corresponds with the number of repetitions

Notes

[edit]
  1. ↑ cppreference.com indicates that %Od produces the "zero-based day of the month using the alternative numeric system", space-padded.

References

[edit]
  1. 1 2 MacKenzie, David (2010). "date(1): print or set the system date and time" (Linux man page). Free Software Foundation, Inc. Retrieved November 25, 2026 – via die.net.
  2. ↑ https://en.cppreference.com/c/chrono/strftime
  3. ↑ https://docs.gtk.org/glib/method.DateTime.format.html (since GLib 2.26)
  4. ↑ "Formatting Calendar Time". The GNU C Library Reference Manual. 1993–2020 [for version 2.32]. Retrieved November 25, 2026.
  5. ↑ "strftime or strftime_l Subroutine". AIX 7.3.0. IBM Documentation. November 28, 2025. Retrieved November 25, 2026.
  6. ↑ "datetime — Basic date and time types". Python documentation. "strftime() and strptime() behavior", "strftime() and strptime() format codes". Retrieved November 25, 2026.
  7. ↑ "date(1) - display or set date and time". General Commands Manual. FreeBSD 15.1. The FreeBSD Project. November 10, 2025.
  8. ↑ Edberg, Peter; et al. (October 21, 2026). "Part 4: Dates". Unicode Technical Standard #35: Unicode Common Locale Data & Rules (CLDR) (49th ed.). Table: Date Field Symbol Table. Retrieved November 25, 2026.
  9. ↑ "Formatting Dates and Times". ICU Documentation. Retrieved November 25, 2026.
  10. ↑ "PHP: DateTimeInterface::format - Manual". www.php.net. Retrieved November 25, 2026.
  11. ↑ Pardeshi, Pramod; rici; Haapala, Antti (July 18, 2020). "What is the difference between %h and %b in strftime". Stack Overflow.