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

155
Visualizações
Incorrect date input being stored within state

I am getting confused with javascript dates but within my app, I am using the following npm package: rc-datepicker

Here the user clicks on a date, which is 21/11/2021 but for some reason, within state, it is being stored as:

2021-11-20T23:25:43.223Z

which is the day prior.

I have got a console log of the date that is being passed through, which is in the following format:

Sun Nov 21 2021 10:25:46 GMT+1100 (Australian Eastern Daylight Time)

Can someone pls assist on how to ensure that the 21/11/2021 is returned and ignore the timezone, if that is the issue or something else?

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

0

Because you are on AEDT (me too!) your dates will show in your timezone.

As pilchard mentioned in the comment, 2021-11-20T23:25:43.223Z is GMT so that's like the start point. Us being +11 means those two representations of time above are actually at the same point in time.

Let's look at what happens with those dates you have.

If you call:

const d = new Date("2021-11-20T23:25:43.223Z")
console.log(d.toString()) // Prints the local representation: Sun Nov 21 2021 10:25:43 GMT+1100 (Australian Eastern Daylight Time)

console.log(d.toISOString()) // Prints in ISO formatted string

Have a look at other date object methods.

So store that string (eg. "2021-11-20T23:25:43.223Z") which represents the same point in time anywhere in the world. Then convert it to the user's local timezone

const d = new Date("2021-11-20T23:25:43.223Z")

You can use other methods such as toLocaleDateString in the link above to specify a particular timezone. The timezone component can be one from the tz database. There is a list of them on wikipedia.

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