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

340
Visualizações
wrong date on conversion toISOString()

I am confused why on converting 8/20/2021 to ISO (cosmosDB format) I am getting 2021-08-19T18:30:00.000Z

const event = new Date('8/20/2021');
console.log(event.toISOString()); //"2021-08-19T18:30:00.000Z"

all the date are saved as string in my cosmosdb and hence I was not able to filter based on given date range and as result we ended up converting string to Date but now when I am trying to convert in to cosmos db expected format it gives me incorrect or may be correct date to update my database.

should I go ahead and update DB to 2021-08-19T18:30:00.000Z in place of 8/20/2021? or it should be 2021-08-20T00:00:00.000Z?

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

0

The value you are passing to Date() is vague. It's being parsed as a date for the timezone for the computer's locale.

When you convert to an ISO string, it's being displayed in UTC, which is 5 and a half hours behind that local time zone.

  • Be more specific when you pass the string to Date()
  • Consider converting the date to the user's local time zone when you read it back from the database
about 4 years ago · Juan Pablo Isaza Relatório

0

The Date.parse() method parses a string representation of a date, and returns the number of milliseconds since January 1, 1970, 00:00:00 UTC

Try this

const event = Date.parse('8/20/2021');
console.log(event) // expected output: 818035920000

Now you can store that in your db.

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