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 @   唯一念  阅读(596)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 【.NET】调用本地 Deepseek 模型
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· 我与微信审核的“相爱相杀”看个人小程序副业
· DeepSeek “源神”启动!「GitHub 热点速览」
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库
点击右上角即可分享
微信分享提示