[英]Convert seconds to Timestamp, and compare values, Firebase, React
I need to compare two values, as you see in my code below.我需要比较两个值,如下面的代码所示。
Point is that they are in different formats, and i need them to compare.关键是它们的格式不同,我需要它们进行比较。
Here is my code(daysToLeave is allways number 1-3 - this value match 1-3 days):这是我的代码(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");
}
use moment and.diff().使用时刻和.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.