python读Excel遇到的日期问题

用Python直接冲Excel中读取数据是,不做任何的处理,遇到日期字段时,会出现误差

当要读取年月日是,可做如下的处理

import datetime

__s_date = datetime.date(1899, 12, 31).toordinal() - 1


def getdate(date):
    if isinstance(date, float):
        date = int(date)
    d = datetime.date.fromordinal(__s_date + date)
    return d


getdate(参数为从Excel中读取到的数据)

遇到时分秒时,简单做法是在Excel时分秒字段数据前加英文单引号'

猜你喜欢

转载自blog.csdn.net/qq_41292236/article/details/103428325