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

180
Views
Removing seconds from Live clock using JavaScript

I was wondering if it is possible to remove the seconds group in a live clock made with JavaScript. Ive been tinkering with it for a while now and have not been successful so far. Any advice or guidance well be gratefully welcomed.

Here's what I'm working with...

function myClock() {
  setTimeout(function() {
    const date = new Date();
    const timeOutput = date.toLocaleTimeString();
    document.getElementById("demo").innerHTML = timeOutput;
    myClock();
  }, 1000)
}
myClock();
<div id="demo"></div>

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You could just split your timeOutput and then grab the hour and minutes, like so:

function myClock() {         
    setTimeout(function() {   
      const date = new Date();
      const dateString = date.toLocaleTimeString('en-GB', {hour12: false});
      const split = dateString.split(":");
      const hour = parseInt(split[0]);
      const min = parseInt(split[1]);
      const period = hour < 12 ? 'AM' : 'PM';
      const timeOutput = hour + ':' + min + ' ' + period;
      document.getElementById("demo").innerHTML = timeOutput; 
      myClock();
    }, 1000)
}
  
myClock();
<div id="demo"></div>

about 4 years ago · Juan Pablo Isaza 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!