Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,096 questions

40,778 answers

573 users

How to check if a date is 24 hours old in JavaScript

2 Answers

0 votes
let OneDay = new Date().getTime() + (1 * 24 * 60 * 60 * 1000);
d = new Date(2020, 4, 20);
                 
if (OneDay > d) {
		console.log(d  + " < one day"); 
}
else if (OneDay < d) {
	console.log(d + " > one day"); 
}
              




/*
run:

Wed May 20 2020 00:00:00 GMT+0300 (Israel Daylight Time) < one day

*/

 





answered May 20, 2020 by avibootz
0 votes
let OneDay = new Date().getTime() + (1 * 24 * 60 * 60 * 1000);
d = new Date(2020, 4, 22);
                 
if (OneDay > d) {
		console.log(d  + " < one day"); 
}
else if (OneDay < d) {
	console.log(d + " > one day"); 
}
              




/*
run:

Fri May 22 2020 00:00:00 GMT+0300 (Israel Daylight Time) > one day

*/

 





answered May 20, 2020 by avibootz

Related questions

1 answer 46 views
1 answer 62 views
...