Check if a date is 24 hours old
Created Example For One hour Refer This and Then Change it to 24 Hours
const OneHourAgo= (date) => {
const hour= 1000 * 60 * 60;
const hourago= Date.now() - hour;
return date > hourago;
}
Simple One:-
var OneDay = new Date().getTime() + (1 * 24 * 60 * 60 * 1000)
day hour min sec msec
if (OneDay > yourDate) {
// The yourDate time is less than 1 days from now
}
else if (OneDay < yourDate) {
// The yourDate time is more than 1 days from now
}
Using moment will be much easier in this case, You could try this:
let hours = moment().diff(moment(yourDateString), 'hours');
let days = moment().diff(moment(yourDateString), 'days');
It will give you integer value like 1,2,5,0etc so you can easily use condition check like:
if(hours >= 24) { your code }
or
if(days >= 1) { your code }
Also, one more thing is you can get more accurate result of the time difference (in decimals like 1.2,1.5,0.7etc) to get this kind of result we need to pass 3rd argument which i.e. true for precise result use this syntax:
let hours = moment().diff(moment(yourDateString), 'hours', true);
Let me know if you have any further query