背景
通過js的xlsx第三方插件來讀取excel中的數據,發現時間這一欄的數據只是一個整數,而這個整數既不是時間戳也不是時間。
解決
- 這個整數值是日期距離1900年1月1日的天數,所以我們需要轉換
//timeValue是指excel中的時間整數值
function formatDate(timeValue) {
let time = new Date((timeValue- 1) * 24 * 3600000 + 1)
time.setYear(time.getFullYear() - 70)
let year = time.getFullYear() + ''
let month = time.getMonth() + 1 + ''
let date = time.getDate() + ''
return year + "-" + month + "-" + date
}