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

209
Visualizações
input "datetime-local" > js code that can update the current time automatically without having to click and select

i am trying to create a script that can update the current time automatically in the datetime-local input without having to click and selecting the current time. this is the code that i am working with to have the input display the current date and time, but i also want it to update the current time when the time changes.

then i hope to submit the datetime-local value to the database using PHP (i got this section covered)

and i was hoping if it's possible to delete the date and time selection button in the input and how can i show the seconds, but have the seconds running accurately with current time

thank you all.

var now = new Date();
now.setMinutes(now.getMinutes() - now.getTimezoneOffset());
document.getElementById('dt').value = now.toISOString().slice(0,16);
<input id="dt" type="datetime-local" />

about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

I think you can set an interval every second for this.

 functionName(); //First execution
 setInterval(functionName, 1000); //Check every second

function functionName(){
   var now = new Date();
   now.setMinutes(now.getMinutes() - now.getTimezoneOffset());
   document.getElementById('dt').value = now.toISOString().slice(0,16);
}
<input readonly id="dt" type="datetime-local" />

Of course you will need to "Stop" this interval when the user clicks on the input, or the date can never be changed

EDIT: For avoid the user to change the date, just add readonly attribute to the input tag.

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