js讀取excel中日期格式轉換問題


在使用js-xlsx插件來讀取excel時,會將2018/10/16這種數據自動裝換成48264.12584511.

所以需要自己手動再轉換回來

// excel讀取2018/01/01這種時間格式是會將它裝換成數字類似於46254.1545151415 numb是傳過來的整數數字,format是之間間隔的符號
    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 < 10 ? '0' + month : month) + (date < 10 ? '0' + date : date)
    },
  console.log(
formatDate(42618, '/')) // 2016-9-5

關於excel導入導出以及該方法的具體使用請瀏覽https://www.cnblogs.com/cazj/p/10912439.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM