1var d = new Date("2020-04-13T00:00:00.000+08:00"); /* midnight in China on April 13th */
2d.toLocaleString('en-US', { timeZone: 'America/New_York' });
3//=> "4/12/2020, 12:00:00 PM"
4// (midnight in China on April 13th is noon in New York on April 12th)
1function utcConverterToLocalTimezone(fechaUTC) {
2 const localTimezone = fechaUTC
3 .toLocaleString({ timeZone: "America/Guayaquil" })
4 .split(" ");
5
6 const diamesaño = localTimezone[0].split("/");
7 let dia = diamesaño[0];
8 let mes = diamesaño[1];
9 const año = diamesaño[2];
10 const hora = localTimezone[1];
11
12 dia < 10 ? (dia = `${0}${dia}`) : null;
13 mes < 10 ? (mes = `${0}${mes}`) : null;
14
15 const fechaFinalFormateada = `${año}-${mes}-${dia}T${hora}-05:00`;
16 return fechaFinalFormateada;
17}
18
19console.log(utcConverterToLocalTimezone(new Date("2021-08-12T03:46:00.000+00:00")));