Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a created date. I want to run an if/switch statement to know whether the date and time right now is more than 24 hours from the created date.

If the created date is more than 24 hours ago, do something, if it's less than 24 hours ago do something else.

let now = +new Date();

// This is returned as: July 18, 2018 at 3:48:00 AM UTC+1
let createdAt = +doc.data().created_at;

const oneDay = 60 * 60 * 24;
var compareDatesBoolean = (now - createdAt) > oneDay;

Any guidance here would be great thank you! :)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
258 views
Welcome To Ask or Share your Answers For Others

1 Answer

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
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...