这个日期格式是什么?44303.02359。new Date() 无法解析它。

huangapple go评论58阅读模式
英文:

What is this date format? 44303.02359 . new Date() can't parse it

问题

Google Sheets可以识别44303.02359的日期格式为4/17/2021,但JavaScript的new Date()无法识别,它认为这是1969年的日期。请问这个日期的格式是什么?我应该如何在JavaScript中解析它?

英文:

I have a list of dates in the format of 44303.02359 and google sheets is able to determine that it's 4/17/2021 but javascript new Date() is unable to, it thinks it's in 1969. My google search for "Two number date separated with a period" isn't proving helpful.

What format is this? How can I parse it with javascript?

答案1

得分: 1

这是一个Excel日期的“序列号”

> 默认情况下,1900年1月1日是序列号1,2008年1月1日是序列号39448,因为它距离1900年1月1日已经过去了39,447天。

来源:https://support.microsoft.com/en-us/office/datevalue-function-df8b07d4-7761-4a93-bc33-b7471bbff252

有一个很棒的短转换函数

function ExcelDateToJSDate(date) {
    return new Date(Math.round((date - 25569) * 86400 * 1000));
}

来源:https://stackoverflow.com/a/22352911/7549483

英文:

It is an Excel date "serial number"

> By default, January 1, 1900 is serial number 1, and January 1, 2008 is serial number 39448 because it is 39,447 days after January 1, 1900.

Source: https://support.microsoft.com/en-us/office/datevalue-function-df8b07d4-7761-4a93-bc33-b7471bbff252

There is a great short converter function

function ExcelDateToJSDate(date) {
    return new Date(Math.round((date - 25569)*86400*1000));
}

Source: https://stackoverflow.com/a/22352911/7549483

huangapple
  • 本文由 发表于 2023年4月6日 23:39:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/75951347.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定