HomeDocs › %p

Python strftime directive %p

Locale’s equivalent of AM or PM.

Example (from datetime(2026, 6, 18, 13, 45, 30))
PM
Output depends on the active locale. This page shows the C/English value; switch locales in the tester to see others.

In Python

from datetime import datetime
dt = datetime(2026, 6, 18, 13, 45, 30)
dt.strftime("%p")
# => "PM"

Parsing with strptime

Parses AM/PM; affects how %I is interpreted. See strptime.dev for the parsing side.

Try %p in the live tester →

Other Time directives