作者: 文章来源:
本文原地址:https://www.mimiwuqi.com/biji/194860.html
在Excel中,日期是以1900年1月1日作为他的起点的数字表示的。所以,因为Excel他认为认为1900年是闰年,所以我们要处理一下
export default function excelDateToJSDate(serial) {
let days = Math.floor(serial - 25569);//25569是从1970年1月1日开始
let timestamp = days * 24 * 60 * 60 * 1000;
let date = new Date(timestamp);//将时间戳转换成时间 格式为:2021-11-01
//下面是判断是否是闰年
if (serial < 61) {
timestamp += 24 * 60 * 60 * 1000;//如果是闰年就加一天
date = new Date(timestamp);//将时间戳转换成时间 格式为:2021-11-03
}
return date;
}
更多 建站笔记 请访问 https://www.mimiwuqi.com/biji/