Reputation: 185
I have a time displayed on my webpage, and im trying to do an action if the time value i have is 5 minutes or older than the current time.
var date1 = new Date(1625807904*1000); // 1625807904 is my date and time
var convert = date1.getDate()+"/"+(date1.getMonth()+1)+"/"+date1.getFullYear()+" "+date1.getHours()+ ":"+ (date1.getMinutes()<10?'0':'') + date1.getMinutes()+ ":"+(date1.getSeconds()<10?'0':'')+date1.getSeconds();
Just my concept
if ( convert < 5minutes or older than the current time){
**** do something ****
}
Thank you for your time !!!
Upvotes: 3
Views: 2629
Reputation: 9903
You can subtract two Date
in JavaScript. The default value is based on millisecond:
var date = new Date(1625807904*1000);
console.log('diffrences based on milliseconds', Date.now() - date)
console.log('diffrences based on minutes', (Date.now() - date) /(60 * 1000))
if((Date.now() - date) <= (5 * 60 * 1000))
{
console.log("your condition is meeted. Do your ACTION")
}
Upvotes: 6