Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

138
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda