Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

156
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda