js 导入excel数据 时间转换

废话不多说,直接上代码:

formatDate (timeNum) {
const time = new Date(((Number(timeNum) - 70 * 365 - 19) * 24 * 3600 - 8 * 3600 - 42.5) * 1000)
const year = time.getFullYear()
const month = time.getMonth() + 1
const date = time.getDate()
const hour = time.getHours()
const min = time.getMinutes()
const sec = time.getSeconds()
const dateArr = [
year,
(month < 10 ? '0' + month : month),
(date < 10 ? '0' + date : date),
]
const timeArr = [
(hour < 10 ? '0' + hour : hour),
(min < 10 ? '0' + min : min),
(sec < 10 ? '0' + sec : sec),
]
return `${dateArr.join('-')} ${timeArr.join(':')}`
}

亲测有效哈~
posted @ 2023-01-28 11:19  唯一念  阅读(542)  评论(0编辑  收藏  举报