Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

173
Visualizações
covnert european time format to US timeformat withAM/PM

I have a string I am trying to display in EST time with AM / PM additions. Somehow it is not working the way I want it to.

I tried this:

let item = "2022-02-16T20:08:29"

return item.toLocaleString("en-US", {
    timeZone: "EST"
  });

expected output 2/16/2022, 8:08:29 PM

output I am getting 2022-02-16T20:08:29

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

item is just a string, when you call toLocaleString() on it, the Object#toLocaleString() method gets called, which just returns the toString().

If you first create a Date object from your item, your code works, and the Date#toLocaleString() method is called:

let item = "2022-02-16T20:08:29"

let usDate = (new Date(item)).toLocaleString("en-US", {
  timeZone: "EST"
});

console.log(usDate)

If you just need the time, you can use Date#toLocaleTimeString():

let item = "2022-02-16T20:08:29"

let usDate = (new Date(item)).toLocaleTimeString("en-US", {
  timeZone: "EST"
});

console.log(usDate)

about 4 years ago · Juan Pablo Isaza Relatório

0

The time you are converting is still a string, to access the method toLocaleString you need to be accessing the Date Object.

The date object accepts a string to parse in the constructor as follows. If you need to convert timezone, then you will need to add in the timezone parameter.

let item = '2022-02-16T20:08:29';

function formatDate(date_string){
  let date = new Date(date_string);
  return date.toLocaleString("en-US");
}

console.log(formatDate(item))
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda