Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

140
Vistas
How to check if value is 10 or more minutes from now?

I'd like to check if value is 10 or more mins from now.

let now = new Date().getTime();
let TEN_MINUTES = new Date().getTime() + 600000;

let val = '2022-01-14 12:27:05+00:00'


if(val > TEN_MINUTES){
   console.log('true')
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

val is a non-blank string, so val > tenMinsPlus doesn't make any sense, since tenMinsPlus is a boolean.

If you want to know whether val is more than ten minutes from now, you need to get a date-like value for val and a date-like value for ten minutes from now, and compare them.

You're getting TEN_MINUTES correctly:

let TEN_MINUTES = new Date().getTime() + 600000;

although you can do that more concisely:

let TEN_MINUTES = Date.now() + 600000;

Both of those give us a number of milliseconds since The Epoch (Jan 1st 1970 at midnight UTC) for "now" plus ten minutes.

Now let's do the date. Your string is almost in a valid format for the Date object to parse. It just needs the space after the date changed into a T, then we can use Date.parse to parse it and give us the number of milliseconds since The Epoch:

let then = Date.parse(val.replace(" ", "T"));

Then we see whether then is greater than TEN_MINUTES:

if (then > TEN_MINUTES) {
    // Yes, it's more than ten minutes from now
} else {
    // No, it isn't
}

Live Example:

function moreThan10Minutes(val) {
    let TEN_MINUTES = Date.now() + 600000;
    let then = Date.parse(val.replace(" ", "T"));
    return then > TEN_MINUTES;
}
function test(val) {
    const result = moreThan10Minutes(val);
    if (result) {
        console.log(`Yes, ${val} is more than 10 minutes from now`);
    } else {
        console.log(`No, ${val} is not more than 10 minutes from now`);
    }
}

test("2022-01-14 12:27:05+00:00");
test(new Date(Date.now() + 700000).toISOString());

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda