How can I convert 'Jan' to an integer using Datetime? When I try strptime, I get an error time data 'Jan' does not match format '%m'
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
You will get the number of month 6
This is straightforward enough that you could consider just using a dictionary, then you have fewer dependencies anyway.
You have an abbreviated month name, so use
%b
:%m
is for a numeric month.However, if all you wanted to do was map an abbreviated month to a number, just use a dictionary. You can build one from
calendar.month_abbr
:Demo:
Off the cuff- Did you try
%b
?