简体   繁体   中英

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):

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");
}

Here are my console.logs: 在此处输入图像描述

use moment and.diff().

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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