Python strftime Formatter
Format a date with any Python strftime pattern — or paste an example and detect the strptime format string. Works for full dates and time-only values.
Input
Output
from datetime import datetime
dt = datetime(2024, 1, 15, 13, 45, 30)
print(dt.strftime('%Y-%m-%d %H:%M:%S')) # 2024-01-15 13:45:30 strftime directive reference
Click a row to add it to your formatExample values are computed from the date currently selected above.
| %d | Day of the month, zero-padded (01–31) | 15 |
| %-d | Day of the month, no padding (1–31) — platform-specific | 15 |
| %a | Weekday name, abbreviated (Sun–Sat) | Mon |
| %A | Full weekday name (Sunday–Saturday) | Monday |
| %w | Weekday as a number (0 = Sunday … 6 = Saturday) | 1 |
| %u | ISO weekday (1 = Monday … 7 = Sunday) | 1 |
| %j | Day of the year, zero-padded (001–366) | 015 |
| %U | Week of year, Sunday-first (00–53) | 02 |
| %W | Week of year, Monday-first (00–53) | 03 |
| %V | ISO-8601 week of year (01–53) | 03 |
| %m | Month, zero-padded (01–12) | 01 |
| %b | Month name, abbreviated (Jan–Dec) | Jan |
| %B | Full month name (January–December) | January |
| %Y | Year with century (e.g. 2024) | 2024 |
| %y | Year without century, zero-padded (00–99) | 24 |
| %G | ISO-8601 week-numbering year | 2024 |
| %H | Hour, 24-hour clock, zero-padded (00–23) | 13 |
| %I | Hour, 12-hour clock, zero-padded (01–12) | 01 |
| %p | AM or PM | PM |
| %M | Minute, zero-padded (00–59) | 45 |
| %S | Second, zero-padded (00–59) | 30 |
| %f | Microsecond, zero-padded to 6 digits | 000000 |
| %z | UTC offset ±HHMM (+0000 in this tool) | +0000 |
| %Z | Timezone name (UTC in this tool) | UTC |
| %c | Locale date and time (C locale) | Mon Jan 15 13:45:30 2024 |
| %x | Locale date (C locale, MM/DD/YY) | 01/15/24 |
| %X | Locale time (C locale, HH:MM:SS) | 13:45:30 |
| %% | A literal % character | % |
About Python strftime Formatter
Python strftime Formatter is a free, two-way playground for Python date formatting. In Python you turn a date into a string with datetime.strftime(), using percent-prefixed directives such as %Y for the four-digit year, %m for the month, and %H:%M:%S for the time. Remembering every directive is tedious — this tool lets you experiment and see the exact output instantly, the same value Python would produce.
It also works in reverse. Paste an example like 00:00:00 and the detector reports the matching format string %H:%M:%S, ready to drop into datetime.strptime(). That makes it just as useful for parsing dates as for formatting them. Everything runs in your browser — nothing is sent to a server.
How to Use Python strftime Formatter
Format a date
- Pick a date and time, or press Now.
- Type a format string or click a common-format chip.
- Read the live output and the per-directive breakdown.
- Copy the ready-to-paste Python snippet.
Detect a format
- Switch to Detect format.
- Paste an example value such as a date or time.
- Review every matching strftime format string.
- Press Use to load it into format mode, or copy it.
Tip: standard strftime always zero-pads numbers. To drop the padding use %-d on Linux/macOS or %#d on Windows, and use %% to print a literal percent sign.
FAQ
What is the difference between format and detect mode?
Format mode is the classic direction: you pick a date and a strftime format string (like %Y-%m-%d %H:%M:%S) and instantly see the output, the same result Python returns from datetime.strftime(). Detect mode is the reverse: you paste an example such as 00:00:00 and the tool tells you the matching format string is %H:%M:%S, ready to use with datetime.strptime().
Does this match Python exactly?
The directives follow the official Python datetime strftime/strptime reference. All date and time codes (%Y, %m, %d, %H, %M, %S, and so on) are computed in UTC so the output is deterministic. Locale-dependent directives (%a, %A, %b, %B, %p, %c, %x, %X) use the C/POSIX (English) locale, which is what most systems use by default.
How do I remove leading zeros, like "1" instead of "01"?
Standard strftime always zero-pads, so there is no portable directive for it. On Linux and macOS you can prefix with a dash — %-d, %-m, %-I — to drop the padding, and on Windows you use a hash, %#d. This tool understands both and the detector returns the dash form when an example has no padding (for example 3:30 PM detects as %-I:%M %p).
Why does an example return more than one format?
Some inputs are genuinely ambiguous. 01/02/2024 could be %d/%m/%Y (2 January) or %m/%d/%Y (1 February). The detector shows every pattern that reproduces your example exactly so you can choose the right one.
What about timezones and %z / %Z?
A plain datetime in Python is "naive" and prints nothing for %z and %Z. Because this tool works with a fixed wall-clock, it treats the value as UTC and reports +0000 for %z and UTC for %Z. To get a real offset in Python, attach a tzinfo (for example datetime.now(timezone.utc)).
How do I print a literal percent sign?
Use %% — two percent signs produce a single literal % in the output.