【发布时间】:2020-05-07 17:58:40
【问题描述】:
我想按天比较两个 Iso 字符串日期,日期格式如下:
**
“2020-05-07T15:51:28.124Z”
**
我做了这个函数来得到按天比较的结果:
compareDatesByDays(higherDate, lowerDate) {
const diffTime = Math.abs(higherDate - lowerDate)
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24))
return diffDays
}
Math.abs 给出 NaN,我认为这不适用于字符串 iso 日期!!
【问题讨论】:
-
finding the difference between two dates in days 上已经有很多问题了。请注意,您的算法意味着相差 1 毫秒的日期将返回 1 天的差异。
标签: javascript date iso toisostring