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

129
Visualizações
I would like to check if the current time is before 11:00 with moment.js. How can I achieve this?

I'm working with the moment.js library, If I want to check if the current time is less than 11:00 or not How do I achieve this?

let  todaysDate = moment() // "yyyy-mm-dd"
var time = "22:59";  // set condition to just before 11:00
var elevenOclockTimeCheck = moment(todaysDate).startOf(time); 
 
// check to see if time is equal or greater to 11:00 PM
console.log(elevenOclockTimeCheck);

// If it is before 11:00 then execte if block
                
if (todaysDate < elevenOclockTimeCheck) {

}
about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

You can use from below code:

moment().isBefore(moment({ hour:11, minute: 0}));
about 4 years ago · Juan Pablo Isaza Relatório

0

Note that you don't need moment.js for this - straight js date / time manipulation will get it done.

const todaysDate = new Date();
const hours = todaysDate.getHours();
const isBefore11 = hours <= 11;
const result = `The time ${isBefore11 ? 'is' : 'is not'} before 11`;

console.log(result);
// my current time is 11:02pm (23:02)- so this consoles 'The time is not before 11'

about 4 years ago · Juan Pablo Isaza Relatório

0

Just call the .hour getter and compare

moment().hour() < 11;
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