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

109
Vistas
Trying to represent date object in another timezone

So basically I have a user enter a date and time for an event start. Later on the user picks a location and I want to display that same time but in a different timezone (For example if the user picks 5PM and picks New York as a location, the UTC date should be 5PM in New York 's timezone).

What I am doing right now is the following:

//utcDate is the date the user picked, I'm just extracting its date and time in this test string, I know this is not how I should parse the string but it is just for test purposes. It returns 2021-29-11 18:00:00. 
const zonedDateString = `${utcDate.getFullYear()}-${utcDate.getMonth()}-${utcDate.getDate()} ${utcDate.getHours()}:${utcDate.getMinutes()}0:00`
//newTimezone is America/New_York, zonedTimeToUtc is a function from date-fns-tz
const newDate = zonedTimeToUtc(zonedDateString, newTimezone) 
// The result for newDate is 2021-11-29T18:00:00Z

Any idea why this isnt working? It is basically just attaching a Z to the end of the string and not adapting it to the timezone.

about 4 years ago · Juan Pablo Isaza
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