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

518
Visualizações
HTML5: input type duration

Is there a way to use input type duration. I am trying to make a input in a way, a user to add time duration something like this 06:30:27:15 ( hh:mm:ss:ms ) and should allow only (0-23:0-59:0-59:0-59).

any help appreciated!

NOTE!: I want to implement this in Angular2+.

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

Sadly, neither HTML inputs nor JavaScript itself support a duration data type. <input type="time"> is for a time of the day, and may display AM/PM selectors depending on your locale.

Your best bet is to work with a text input and to use JavaScript events to automatically insert : and ignore invalid inputs. Using the pattern attribute may also help. Be sure to convert the value to a number before using it from the JavaScript side of things. Here's something to get you started.

{
  let durationIn = document.getElementById("duration-input");
  let resultP = document.getElementById("output");
  
  durationIn.addEventListener("change", function (e) {
    resultP.textContent = "";
    durationIn.checkValidity();
  });
  
  durationIn.addEventListener("invalid", function (e) {
    resultP.textContent = "Invalid input";
  });
}
input:invalid:not(:focus) { background: red; }
<input id="duration-input" type="text" required pattern="[0-9]{2}:[0-9]{2}:[0-9]{2}:[0-9]{2}" value="00:00:00:00" title="Write a duration in the format hh:mm:ss:ms">

<p id="output"></p>

I'm sure there are many open-source libraries which provide a ready-made widget for that.

over 4 years ago · Santiago Trujillo Relatório

0

Maybe try something like this:

<input type="time" step="0.001">
over 4 years ago · Santiago Trujillo Relatório

0

<label for="appt">Choose a time for your meeting:</label>

<input type="time" id="appt" name="appt"
       min="09:00" max="18:00" required>

<small>Office hours are 9am to 6pm</small>

Try this... I hope this helps ! This is something I did for one of my projets...

over 4 years ago · Santiago Trujillo 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