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

156
Visualizações
I need to remove seconds from a javascript file based on time

I have looked up how to remove seconds from javascript time fetch. I have checked the worldclock API website. I am not familiar with JS, so I dont know the right question to input into search. Here is my code, I was hoping someone could point me in the right direction to remove seconds from the received output.

I want to go from HH:MM:SS to just HH:MM. I would appreciate any help. Thank you

window.onload = (ev => {
   getTime().then();
});
let count = 0;

async function getTime(){
    count+=1;
    let data = await fetch('https://worldtimeapi.org/api/timezone/Etc/GMT+3'); 
    let res = await data.json();
    let result = res.datetime.toString();
    let time = result.substring(11,19)

    let digital_clock = document.getElementById('content')
    digital_clock.innerHTML = time;
    getTime().then();
    console.log(count);
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

to uh... well, let's get to it.

Change this line:

let time = result.substring(11,19)

...to this line:

let time = result.substring(11,16)

What we're doing here is shortening the extracted string to include just hours and minutes.

about 4 years ago · Juan Pablo Isaza Relatório

0

You can convert the datetime to Date Object and then you have access to some methods. Afterwards you can build your own date what you wish.

fetch('https://worldtimeapi.org/api/timezone/Etc/GMT+3')
  .then(data => data.json())
  .then(data => {
    const date = data.datetime
    const res = {
      year: new Date(date).getFullYear(),
      month: new Date(date).getMonth() + 1,
      day: new Date(date).getDate(),
      hours: new Date(date).getHours(),
      minutes: new Date(date).getMinutes()
    }
     console.log(res)
})

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