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

162
Visualizações
How convert timestamp to specific date and time format with Javascript

From api I get a timestamp returned like: 1643295022

How do I convert it to 2020-08-26T08:46:01+02:00 with Javascript?

export const generateDate = (time: number) => {
  return new Date(time * 1000);
};

The above returns Fri Jan 28 2022 12:57:00 GMT+0100 (Central European Standard Time). How do I convert it into something like 2022-01-27T14:50:22+02:00?

Also for another helper I am using already date-fns. Maybe I can use it in this case?

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

0

I think what you are looking for is an ISO formatted Date but with the Time Zone Offset information.

You can obtain the time zone offset with the getTimezoneOffset() then append it to the end of the date format obtained from the toISOString() after removing the seconds string after the ..

Because the result of the getTimezoneOffset() is in minutes you need to convert it into HH:MM with the necessary + and - signs.

Hope the following is of help.

const isoWithTimeZone = d => {
let TZ=(d=new Date(d*1000)).getTimezoneOffset(), a=Math.abs(TZ);
return d.toISOString().split(".")[0]+(TZ<0?"+":"-")+("00"+~~(a/60)).slice(-2)+":"+("00"+a%60).slice(-2);
}

console.log(isoWithTimeZone(1643295022));

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