Rust chrono tokens.

The de-facto Rust date-time crate

Chrono ships its own strftime implementation, so output is identical on every platform — and the padding overrides %-?, %_? and %0? are documented and portable, unlike their glibc-only cousins in Python. True unpadded tokens don't exist: %e, %k and %l are space-padded, which is not the same thing. The biggest trap is %f, which prints nanoseconds since the last whole second as a bare unscaled number — the dotted %.f family is what you almost always want. There is no era token, and %Z never prints a zone abbreviation.

TokenMeansExample
%YFour-digit year

Zero-padded to four digits; proleptic Gregorian, so negative years are possible.

2006
%yTwo-digit year

Floor division: 100 BCE (year -99) prints 99, with %C giving -1.

06
%mMonth number, padded

The documented %-m modifier form suppresses padding.

01
%bMonth name, abbreviated

Always three letters; %h is a synonym.

Jan
%BMonth name, full

Parsing also accepts the abbreviation.

January
%dDay of month, padded

%e is the space-padded day (same as %_d); %-d suppresses padding entirely.

02
%aWeekday, abbreviated

Always three letters.

Mon
%AWeekday, full

Parsing also accepts the abbreviation.

Monday
%jDay of year

Zero-padded to three digits (001–366).

2
%VWeek of year

ISO-8601 week (01–53; week 0 does not exist). %U (Sunday-first) and %W (Monday-first) count from 00 and disagree around New Year.

1
%GISO week-based year

Pairs with %V; mixing %Y with %V is the classic New-Year bug. %g is the two-digit form.

2006
%HHour, 24-hour clock, padded

%k is the space-padded form (same as %_H); %-H suppresses padding.

15
%IHour, 12-hour clock, padded

%l is the space-padded form (same as %_I).

03
%pAM/PM marker

Uppercase AM/PM; %P gives lowercase am/pm.

PM
%MMinute, padded04
%SSecond, padded

Range is 00–60 because chrono accounts for leap seconds.

05
%.3fFractional seconds

Milliseconds including the leading dot (.026); %.6f and %.9f fix other widths, %3f drops the dot. Bare %f is a trap — nanoseconds as an unscaled number.

000
%zUTC offset, basic

%#z is parsing-only and tolerates missing minutes.

-0700
%:zUTC offset, extended

%::z adds seconds; %:::z drops minutes.

-07:00
%ZTime-zone name, short

Trap: when formatting, this prints the offset, not a zone abbreviation — chrono only knows offsets. Parsing skips any non-whitespace.

MST
%sUnix timestamp

Seconds since 1970-01-01 00:00 UTC.

1136239445
%qQuarter

Single digit, 1–4.

1

Examples render the reference instant, Mon, Jan 2 2006, 3:04:05 PM MST.

Literal text

A literal percent sign must be written %%; %t and %n produce a tab and a newline. Other text passes through literally, but an unrecognized %-sequence makes the whole format string invalid rather than passing through.

Verified against chrono docs — strftime format specifiers.

Translate Rust chrono