Python strftime() cheat sheet & directive reference
Every Python strftime directive with a description and a live example, grouped by what it formats. Examples use datetime(2026, 6, 18, 13, 45, 30).
Open the live tester →
Year
| %Y | Year with century as a decimal number. | 2026 |
| %y | Year without century, zero-padded (00–99). | 26 |
| %-yplatform-specific | Year without century, no leading zero. Platform-specific (Linux/macOS). | 26 |
| %G | ISO 8601 week-based year. Use with %V and %u, never with %Y. | 2026 |
Month
| %m | Month as a zero-padded number (01–12). | 06 |
| %B | Full month name in the current locale. | June |
| %b | Abbreviated month name in the current locale. | Jun |
| %-mplatform-specific | Month with no leading zero. Platform-specific (Linux/macOS). | 6 |
| %h | Equivalent to %b (abbreviated month name). | Jun |
Day
| %d | Day of the month, zero-padded (01–31). | 18 |
| %-dplatform-specific | Day of the month with no leading zero. Platform-specific (Linux/macOS). | 18 |
| %j | Day of the year, zero-padded (001–366). | 169 |
| %-jplatform-specific | Day of the year with no leading zero. Platform-specific (Linux/macOS). | 169 |
Weekday
| %A | Full weekday name in the current locale. | Thursday |
| %a | Abbreviated weekday name in the current locale. | Thu |
| %w | Weekday as a decimal number, 0=Sunday … 6=Saturday. | 4 |
| %u | Weekday as a decimal number, 1=Monday … 7=Sunday (ISO 8601). | 4 |
Time
| %H | Hour (24-hour clock), zero-padded (00–23). | 13 |
| %I | Hour (12-hour clock), zero-padded (01–12). | 01 |
| %p | Locale’s equivalent of AM or PM. | PM |
| %M | Minute, zero-padded (00–59). | 45 |
| %S | Second, zero-padded (00–59; up to 61 historically for leap seconds). | 30 |
| %-Hplatform-specific | 24-hour hour with no leading zero. Platform-specific (Linux/macOS). | 13 |
| %-Iplatform-specific | 12-hour hour with no leading zero. Platform-specific (Linux/macOS). | 1 |
| %-Mplatform-specific | Minute with no leading zero. Platform-specific (Linux/macOS). | 45 |
| %-Splatform-specific | Second with no leading zero. Platform-specific (Linux/macOS). | 30 |
| %f | Microsecond as a decimal number, zero-padded to 6 digits (000000–999999). | 000000 |
Time zone
| %z | UTC offset as ±HHMM (empty if the datetime is naive). | |
| %Z | Time zone name or abbreviation (empty if the datetime is naive). | |
Week & ISO
| %U | Week of the year, Sunday as the first day (00–53). Days before the first Sunday are week 0. | 24 |
| %W | Week of the year, Monday as the first day (00–53). Days before the first Monday are week 0. | 24 |
| %V | ISO 8601 week number (01–53). Use with %G and %u. | 25 |
Locale
| %c | Locale’s appropriate date and time representation. | Jun 18, 2026, 1:45:30 PM |
| %x | Locale’s appropriate date representation. | 6/18/26 |
| %X | Locale’s appropriate time representation. | 1:45:30 PM |
Literal
| %% | A literal “%” character. | % |
Names for months, weekdays and AM/PM depend on the active locale;
%z and
%Z are empty for naive datetimes. The same directives are used by
strptime to parse strings back into dates.