12-hour time in Python strftime()
A human-friendly clock time with AM/PM.
Format string
%I:%M %p
Example output
01:45 PM
Edit this format in the live tester →
In Python
from datetime import datetime
dt = datetime(2026, 6, 18, 13, 45, 30)
dt.strftime("%I:%M %p")
# => "01:45 PM"
Directives used
| %I | Hour (12-hour clock), zero-padded (01–12). | 01 |
| %M | Minute, zero-padded (00–59). | 45 |
| %p | Locale’s equivalent of AM or PM. | PM |