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

234
Visualizações
Comparing a moment.js obect to a timestamp from JSON response

I am trying to compare a moment object (30 days ago) to a given timestamp. Both isBefore and isAfter are returning false. Im not sure where i'm going wrong?

var startdate = moment.utc().subtract(30,'days')

var RequestedDate = moment.utc('14/12/2021, 11:26')

var isbefore = startdate.isBefore(RequestedDate)
var isafter = startdate.isAfter(RequestedDate)

console.log(isafter)
console.log(isbefore)
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The requested date is not in the right format, based on the error emitted in a fiddle of your code:

Deprecation warning: value provided is not in a recognized RFC2822 or ISO format. moment construction falls back to js Date(), which is not reliable across all browsers and versions. Non RFC2822/ISO date formats are discouraged. Please refer to http://momentjs.com/guides/#/warnings/js-date/ for more info.

If you're able to use the "Date + Format" constructor, then you can parse something like this:

var RequestedDate = moment.utc('14/12/2021, 11:26', 'D/M/Y, H:m', true)
// "Tue Dec 14 2021 11:26:00 GMT+0000"

Note the use of strict mode, as in the docs:

You may get unexpected results when parsing both date and time. The below example may not parse as you expect:

moment('24/12/2019 09:15:00', "DD MM YYYY hh:mm:ss");
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