Reputation: 19181
Is there a way to convert a string containing the month's name to an integer that is dependent on the current locale?
I know that somedate.strftime("%B")
can convert a date time object to a string containing the month's name according to the current locale but is there way to go backwards?
Upvotes: 3
Views: 365
Reputation: 89867
strptime()
does the inverse of what strftime()
does.
>>> datetime.datetime.strptime("February", "%B").month
2
Upvotes: 6