¿Hay alguna forma de verificar si una fecha es anterior a 1 hora?JS: ¿Verificar si la fecha es menos de 1 hora?
Algo como esto:
<script>
// old date
var olddate = new Date("February 9, 2012, 12:15");
// current date
var currentdate = new Date();
if (olddate >= currentdate - 1 hour) {
alert("newer than 1 hour");
else {
alert("older than 1 hour");
}
</script>
Además, pregunta diferente - ¿Existe una manera de agregar horas a una fecha?
De esta manera:
<script>
var olddate = new Date("February 9, 2012, 12:15") + 15 HOURS; // output: February 10, 2012, 3:15
</script>
su segunda pregunta es un posible duplicado de http://stackoverflow.com/questions/1050720/adding-hours-to-javascript-date-object – Pbirkoff