繁体   English   中英

将秒转换为时间戳,并比较值,Firebase,React

[英]Convert seconds to Timestamp, and compare values, Firebase, React

我需要比较两个值,如下面的代码所示。

关键是它们的格式不同,我需要它们进行比较。

这是我的代码(daysToLeave 总是数字 1-3 - 此值匹配 1-3 天):

const tomorrow = new Date();
const tmp = tomorrow.getDate() + daysToLeave;
tomorrow.setDate(tmp);

console.log("eventDate.date", eventDate?.date);
console.log("tommorrow", tomorrow);

if (eventDate?.date < tomorrow) {
  console.log("success");
}

这是我的控制台日志: 在此处输入图像描述

使用时刻和.diff()。

 //Determine the unit of difference between const type = ["years","months","weeks","days","hours","minutes"] moment(tomorrow).diff(eventDate?.date.toDate(), type[3])

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM