月份转换(数字-英文全称、数字-英文简写,英文全称-数字)

import calendar

#数字转为月份简写
date_list = [1,2,3,4,5,6,7,8,9,10,11,12]
for i in date_list:
    print(calendar.month_abbr[i])

date_list = [1,2,3,4,5,6,7,8,9,10,11,12]

#数字转月份的全写
for i in date_list:
    print(calendar.month_name[i])

# 简写月份转数字

month_abbr_list = ['Jan',
 'Feb',
 'Mar',
 'Apr',
 'May',
 'Jun',
 'Jul',
 'Aug',
 'Sep',
 'Oct',
 'Nov',
 'Dec']

for i in month_abbr_list:
    print( list(calendar.month_abbr).index(i) )
month = list(calendar.month_abbr).index('Dec')

  

posted @ 2022-09-28 16:18  究极不吃香菜  阅读(287)  评论(0编辑  收藏  举报