How can I account for period (AM/PM) using strftime?

The Python time.strftime docs say:

When used with the strptime() function, the %p directive only
affects the output hour field if the %I directive is used to parse
the hour.

Sure enough, changing your %H to %I makes it work.

Leave a Comment