Answers for "convert utc time to specific timezone javascript"

15

javascript set date to timezone

var d = new Date("2020-04-13T00:00:00.000+08:00"); /* midnight in China on April 13th */
d.toLocaleString('en-US', { timeZone: 'America/New_York' });
//=> "4/12/2020, 12:00:00 PM"
// (midnight in China on April 13th is noon in New York on April 12th)
Posted by: Guest on June-17-2020
0

convert utc time to specific timezone javascript

function utcConverterToLocalTimezone(fechaUTC) {
  const localTimezone = fechaUTC
    .toLocaleString({ timeZone: "America/Guayaquil" })
    .split(" ");

  const diamesaño = localTimezone[0].split("/");
  let dia = diamesaño[0];
  let mes = diamesaño[1];
  const año = diamesaño[2];
  const hora = localTimezone[1];

  dia < 10 ? (dia = `${0}${dia}`) : null;
  mes < 10 ? (mes = `${0}${mes}`) : null;

  const fechaFinalFormateada = `${año}-${mes}-${dia}T${hora}-05:00`;
  return fechaFinalFormateada;
}

console.log(utcConverterToLocalTimezone(new Date("2021-08-12T03:46:00.000+00:00")));
Posted by: Guest on August-12-2021

Code answers related to "convert utc time to specific timezone javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language