<
h1
style
=
"color:green;"
>
GeeksForGeeks
</
h1
>
<
p
id
=
"GFG_UP"
style
=
"font-size: 15px; font-weight: bold;"
>
</
p
>
<
button
onclick
=
"gfg_Run()"
>
click here
</
button
>
<
p
id
=
"GFG_DOWN"
style="color:green;
font-size: 20px; font-weight: bold;">
</
p
>
<
script
>
var el_up = document.getElementById("GFG_UP");
var el_down = document.getElementById("GFG_DOWN");
var prev_date = new Date();
var d = new Date();
Date.prototype.addHours = function(h) {
this.setTime(this.getTime() + (h*60*60*1000));
return this;
}
prev_date.addHours(-2);
el_up.innerHTML = "Click on the button to "
+ "check if the date is less than "
+ "1 hour ago.<
br
>Previous date = "
+ prev_date;
function gfg_Run() {
// Hour in milliseconds
var ONE_HOUR = 60 * 60 * 1000;
if ((d - prev_date) <
ONE_HOUR
) {
el_down.innerHTML
=
"Date is less"
+ " than 1 hour ago.";
}
else {
el_down.innerHTML
=
"Date is not "
+ "less than 1 hour ago.";
}
}
</script>