Python strftime tokens.
Python's datetime.strftime inherits the C strftime vocabulary with documented additions (%f). There are no portable unpadded-number tokens: the %-d and %-m forms work on glibc and macOS but fail on Windows, so this table lists only what the documentation guarantees. Month and weekday names follow the process locale, not an argument. There is no %s in the documentation — use datetime.timestamp() for a unix timestamp.
| Token | Means | Example |
|---|---|---|
| %Y | Four-digit year Not zero-padded below year 1000 on all platforms. | 2006 |
| %y | Two-digit year | 06 |
| %m | Month number, padded | 01 |
| %b | Month name, abbreviated | Jan |
| %B | Month name, full | January |
| %d | Day of month, padded | 02 |
| %a | Weekday, abbreviated | Mon |
| %A | Weekday, full | Monday |
| %j | Day of year Zero-padded to three digits (002). | 2 |
| %V | Week of year ISO-8601 week. %U (Sunday-first) and %W (Monday-first) count differently — all three disagree around New Year. | 1 |
| %G | ISO week-based year Pairs with %V; using %Y next to %V is the classic New-Year bug. | 2006 |
| %H | Hour, 24-hour clock, padded | 15 |
| %I | Hour, 12-hour clock, padded | 03 |
| %p | AM/PM marker Locale-dependent; empty in some locales that don't use day periods. | PM |
| %M | Minute, padded | 04 |
| %S | Second, padded | 05 |
| %f | Fractional seconds Always six digits (microseconds), never three. | 000 |
| %z | UTC offset, basic Empty string for naive datetimes; can include seconds/microseconds for exotic offsets. | -0700 |
| %:z | UTC offset, extended Added in Python 3.12; earlier versions need manual slicing. | -07:00 |
| %Z | Time-zone name, short Empty for naive datetimes; the name comes from the tzinfo object. | MST |
Examples render the reference instant, Mon, Jan 2 2006, 3:04:05 PM MST.
Literal text
A literal percent sign is written %%. All other text passes through unchanged; unknown %-sequences are platform-defined, so don't rely on them surviving.
Verified against Python docs — strftime() and strptime() format codes.