0

I'm trying to figure out how to output single digit hour and NOT get a ValueError. When I run the following code:

from datetime import datetime as dt
dt.now().strftime(format="%m/%d/%Y, %-I:%M:%S %p")

I get the following error:

ValueError: Invalid format string

However, this runs just fine:

dt.now().strftime(format="%m/%d/%Y, %I:%M:%S %p")

Output:

'10/11/2022, 09:29:01 PM'

enter code here
april
  • 41
  • 1
  • 5

0 Answers0