[英]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.