Excel time processing function

Generally, the time in the data we get from excel is generally a number, because the excel table has been converted internally

But what should we do if we need to convert it to the format of 2022/12/31? At this time, we need to use this method

// 把excel文件中的日期格式的内容转回成标准时间
export function formatExcelDate(numb, format = '/') {
  const time = new Date((numb - 25567) * 24 * 3600000 - 5 * 60 * 1000 - 43 * 1000 - 24 * 3600000 - 8 * 3600000)
  time.setYear(time.getFullYear())
  const year = time.getFullYear() + ''
  const month = time.getMonth() + 1 + ''
  const date = time.getDate() + ''
  if (format && format.length === 1) {
    return year + format + month + format + date
  }
  return year + (month < 10 ? '0' + month : month) + (date < 10 ? '0' + date : date)
}

We only need to call this method to convert the date into the format we want. 2022/12/31

If you want to convert to more formats, you can use Moment.js Chinese website for processing


 

Guess you like

Origin blog.csdn.net/qq_52006046/article/details/128525685