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

Common formats

Output

Formatted result 2024-01-15 13:45:30
Token breakdown
%Y 2024literal -%m 01literal -%d 15literal %H 13literal :%M 45literal :%S 30
Python code
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 format

Example values are computed from the date currently selected above.

Day
%dDay of the month, zero-padded (01–31)15
%-dDay of the month, no padding (1–31) — platform-specific15
%aWeekday name, abbreviated (Sun–Sat)Mon
%AFull weekday name (Sunday–Saturday)Monday
%wWeekday as a number (0 = Sunday … 6 = Saturday)1
%uISO weekday (1 = Monday … 7 = Sunday)1
%jDay of the year, zero-padded (001–366)015
Week
%UWeek of year, Sunday-first (00–53)02
%WWeek of year, Monday-first (00–53)03
%VISO-8601 week of year (01–53)03
Month
%mMonth, zero-padded (01–12)01
%bMonth name, abbreviated (Jan–Dec)Jan
%BFull month name (January–December)January
Year
%YYear with century (e.g. 2024)2024
%yYear without century, zero-padded (00–99)24
%GISO-8601 week-numbering year2024
Time
%HHour, 24-hour clock, zero-padded (00–23)13
%IHour, 12-hour clock, zero-padded (01–12)01
%pAM or PMPM
%MMinute, zero-padded (00–59)45
%SSecond, zero-padded (00–59)30
%fMicrosecond, zero-padded to 6 digits000000
Timezone
%zUTC offset ±HHMM (+0000 in this tool)+0000
%ZTimezone name (UTC in this tool)UTC
Locale & literal
%cLocale date and time (C locale)Mon Jan 15 13:45:30 2024
%xLocale date (C locale, MM/DD/YY)01/15/24
%XLocale 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

  1. Pick a date and time, or press Now.
  2. Type a format string or click a common-format chip.
  3. Read the live output and the per-directive breakdown.
  4. Copy the ready-to-paste Python snippet.

Detect a format

  1. Switch to Detect format.
  2. Paste an example value such as a date or time.
  3. Review every matching strftime format string.
  4. 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.