Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

207
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda