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

215
Visualizações
Incorrect date conversion of JSON dates using moment, OffSet value is ignored

I am making an api call and getting the below response.

{
    "Country": "U.S.A.",
    "FaceValueCcy": "",
    "IsApproved": true,
    "MDate": "/Date(1742130000000+1100)/",
    "MtmInUsd": 0,
}

When I am trying to convert the MDate into 'DD-MMM-YYYY' format. I am expecting the result as '17-Mar-2025' but it is giving me the output as '16-Mar-2025'. This is the code I am using to convert the date.

moment('/Date(1742130000000+1100)/').utc().format('DD-MMM-YYYY')

When I query the value '1742130000000' in epochconvertor, it gives me 16-Mar-2025. why moment is ignoring +1100? Is there any alternate way to resolve this issue?

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

0

You need to use parseZone() to keep the offset.

console.log(moment.parseZone('/Date(1742130000000+1100)/').utc().format('DD-MMM-YYYY'));

console.log(moment.parseZone('/Date(1742130000000+1100)/').utc().format()); // full time
console.log(moment.parseZone('/Date(1742130000000+1100)/').format()); // full time without UTC conversion
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js"></script>

Reference: https://github.com/moment/moment/issues/3291

about 4 years ago · Juan Pablo Isaza Relatório

0

Use paeseZone

moment('/Date(1742130000000+1100)/').parseZone().format('DD-MMM-YYYY')
about 4 years ago · Juan Pablo Isaza Relatório

0

It should be:

moment.parseZone('/Date(1742130000000+1100)/').format('DD-MMM-YYYY')
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