Parse string according to the given date and time format (like time.strptime()).
For a list of supported format codes, see the documentation:
https://docs.python.org/3/library/datetime.html#format-codes
3.15: If format specifies a day of month (%d) without a year, ValueError is raised. This is to avoid a quadrennial leap year bug in code seeking to parse only a month and day as the default year used in absence of one in the format is not a leap year. The workaround is to always include a year in your format. If parsing date_string values that do not have a year, explicitly add a year that is a leap year before parsing: >>> import datetime as dt >>> date_string = "02/29" >>> when = dt.datetime.strptime(f"{date_string};1984", "%m/%d;%Y") # Avoids leap year bug. >>> when.strftime("%B %d") 'February 29'