Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

120
Views
input "datetime-local" > js code that makes the seconds run/move accurately for time to update

I would like to find out how to have the seconds run/move accurately for the time to change. is there a way I can do that with the js script that I have provided below?

thank you all.

functionName(); //First execution
 setInterval(functionName, 1000); //Ask the browser to execute functionName as soon as possible after 1 second has passed

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

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

Using getSeconds and setSeconds works:

I also changed the string slice to .slice(0,19) to show the updated seconds.

functionName(); //First execution
 setInterval(functionName, 1000); //Ask the browser to execute functionName as soon as possible after 1 second has passed

function functionName(){
   var now = new Date();
   now.setSeconds(now.getSeconds() - now.getTimezoneOffset());
   document.getElementById('dt').value = now.toISOString().slice(0,19);
}
<input readonly="readonly" name="dt" id="dt" type="datetime-local" step="1" />

about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!