python3 csv,xlsx中英语日期打印出数字(float

2020-05-29  本文已影响0人  戒灵

例如csv/xlsx中为:May 07, 2020
正常取出打印为:43958.0
我们想要的为:May 07, 2020

import datetime   #注意这里
def getdate():
    date = 43958.0
    __s_date = datetime.date(1899, 12, 31).toordinal()-1
    if isinstance(date, float):
        date = int(date)
        print(type(date))
    d = datetime.date.fromordinal(__s_date + date)
    print(d)
    d = re.search(r"(\d+)-(\d+)-(\d+)",str(d))
    year = d.group(1)
    mouth = d.group(2)
    days = d.group(3)
    a_list = {'01': 'January', '02': 'February', '03': 'March', '04': 'April', '05': 'May', '06': 'June', '07': 'July',
              '08': 'August', '09': 'September', '10': 'October', '11': 'November', '12': 'December'}
    for k,v in a_list.items():
        if mouth == k:
            d =v+" "+days+','+ " "+year
            print(d) # 打印为 May 07, 2020
上一篇下一篇

猜你喜欢

热点阅读