const firstDate = parseISO(event.start_date); // Here I already have the formatted date
const secondDate = parseISO(event.end_date); // Here I already have the formatted date
const distance = formatDistance(
firstDate ,
secondDate
);我需要传递这两个已经格式化的日期之间的距离。事实上,他指出了我。
此差异与所有数据(日期和时间)
下面是我在api中得到的一个示例
"start_date":"2020-09-23 11:24:14","end_date":"2020-09-24 17:47:41",
发布于 2020-10-09 05:42:00
我对date-fns了解不多,但由于parseISO()返回一个Date对象,你可以用.getTime()的结果做数学运算,得到以毫秒为单位的差值:
const formatDistance = (start, end) => {
return end.getTime() - start.getTime();
}
const distance = formatDistance(
firstDate ,
secondDate
);
console.log(`The two dates are ${distance}ms apart.`);https://stackoverflow.com/questions/64270874
复制相似问题