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

182
Visualizações
How to format a date received from my server using javascript?

I need to format a date with javascript but I'm having a little trouble solving this.

I get two dates, I need to format them and then join the values. On one of the dates I get this:

"2022-07-12T04:00:00-0300"

And on the other date I get this:

"2022-07-12T06:00:00-0300"

These are always dynamic dates returned from my backend, but here on the frontend I need to display these two dates in this following format:

"04:00 - 06:00"
about 4 years ago · Santiago Gelvez
2 Respostas
Responde à pergunta

0

You can use slice() method.

var date1 = "2022-07-12T04:00:00-0300";
var date2 = "2022-07-12T06:00:00-0300";

var formatted = `${date1.slice(11, 16)} - ${date2.slice(11, 16)}`;

console.log(formatted);

about 4 years ago · Santiago Gelvez Relatório

0

This is assuming you only need the hours and minutes.

function datesToRange(start, end) {
  if (!start || !end) return ""; // If either date is null or undefined.
  return start.substring(12, 17) + " - " + end.substring(12, 17);
}

Now you can call this method to get the range in your required format.

E.g.

datesToRange("2022-07-12T04:00:00-0300", "2022-07-12T06:00:00-0300");

Will return "04:00 - 06:00".

about 4 years ago · Santiago Gelvez 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