js转化excel日期(亲测 ~ _~)
因使用js-xlsx读取excel得到的日期不是正常的日期格式,所以从网上找了一下转化的方法,但是没找到一个合适的,下面展示我所采坑的两个方法,分别为百度出来的前两位,望采纳
1. 采坑的两个方法
formatDate(numb, format) {
const time = new Date((numb - 1) * 24 * 3600000 + 1)
time.setYear(time.getFullYear() - 70)
const year = time.getFullYear() + ''
const month = time.getMonth() + 1 + ''
const date = time.getDate() - 1 + ''
if (format && format.length === 1) {
return year + format + month + format + date
}
return year + (month
return year + format + month + format + date
}
return year+(month
return "";
}
let time = new Date(new Date("1900-1-1").getTime() + (numb - 1) * 3600*24*1000);
const year = time.getFullYear() + '';
const month = time.getMonth() + 1 + '';
const date = time.getDate();
if (format && format.length === 1) {
return year + format + (month |