把excel文件中的日期格式的内容转回成标准时间
// 把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)
}
该文章提供了一个JavaScript函数,用于将Excel文件中的日期格式数值转换为标准时间。函数首先计算日期的时间戳,然后创建一个新的Date对象,并调整为正确的年、月、日。最后,根据指定的格式返回格式化的日期字符串。
2万+

被折叠的 条评论
为什么被折叠?



