month name to month number and vice versa in python

后端 未结 12 1177
情书的邮戳
情书的邮戳 2020-11-29 20:13

I am trying to create a function that can convert a month number to an abbreviated month name or an abbreviated month name to a month number. I thought this might be a commo

12条回答
  •  时光取名叫无心
    2020-11-29 20:52

    You can use below as an alternative.

    1. Month to month number:

    from time import strptime

    strptime('Feb','%b').tm_mon

    1. Month number to month:

    import calendar

    calendar.month_abbr[2] or calendar.month[2]

提交回复
热议问题