Básicamente, hago que un usuario ingrese una fecha y hora para el inicio de un evento. Más tarde, el usuario elige una ubicación y quiero mostrar esa misma hora pero en una zona horaria diferente (por ejemplo, si el usuario elige las 5:00 p. m. y elige Nueva York como ubicación, la fecha UTC debe ser las 5:00 p. m. en la zona horaria de Nueva York).
Lo que estoy haciendo ahora mismo es lo siguiente:
//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¿Alguna idea de por qué esto no funciona? Básicamente es simplemente adjuntar una Z al final de la cadena y no adaptarla a la zona horaria.