Python strftime() format tester and directive reference

Format string
Output
06/18/2026 01:45 PM
Reference time: 2026-06-18 13:45:30 (UTC, naive)
Python
from datetime import datetime
datetime.now().strftime("%m/%d/%Y %I:%M %p")
Common formats

Frequently asked questions

What is Python's strftime?
datetime.strftime(format) turns a date/time object into a string using directives like %Y (year) and %H (hour). The reverse, parsing a string into a datetime, is strptime — try strptime.dev.
Why are %z and %Z empty?
A naive datetime has no time-zone info, so those directives produce an empty string. Switch the Datetime control to Aware to see an offset and zone name.
What does %-d do?
It prints the day with no leading zero (6 instead of 06). The - modifier is platform-specific (Linux/macOS) and is not available on Windows.
How do I get the leading zero off the hour or month?
Use %-H, %-m, etc. on Linux/macOS, or strip it in Python with str(int(...)) for portability.