Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8046475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:47:51+00:00 2026-06-05T05:47:51+00:00

ok lets say we have a website that need a realtime time; example :

  • 0

ok lets say we have a website that need a realtime time;

example :

<div id="updatetime">21:12:52</div>

each seconds update hours:m:second.

what i have in minds using the interval function to do long pool and add the sec +1 if to 60 then add + 1 to m and same as hours. but is there a function already solving this problem?

how do you make this 21:12:52 a moving real clock with javascript that updates each seconds?

i have search google, stackoverflow, many of them tells us how to make the current real time datetime from javascript. but none from an existing time. if there is please do insert the link.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T05:47:53+00:00Added an answer on June 5, 2026 at 5:47 am

    It can be as easy as this:

    setInterval(function(){
        document.getElementById("updatetime").innerHTML = (new Date()).toLocaleTimeString();
    }, 1000);
    

    Or use the other Date methods to fine-tune your output.

    Update

    I only now realized that OP was asking not about incrementing an element with the current time but with a predetermined time.

    That’s less trivial, but here is a solution that should fit the original question:

    function increment_time_element(element, delay) {
        var interval, last,
            time_pattern = /(\d+):(\d+):(\d+)/,
            start = element.innerHTML.match(time_pattern),
            then = new Date;
    
        then.setHours  (parseInt(start[1], 10) || 0);
        then.setMinutes(parseInt(start[2], 10) || 0);
        then.setSeconds(parseInt(start[3], 10) || 0);
    
        function now() {
            return Date.now ? Date.now() : (new Date).getTime();
        }
    
        last = now();
    
        interval = setInterval(function () {
            var current = now();
            // correct for any interval drift by using actual difference
            then.setTime(then.getTime() + current - last)
            last = current;
            element.innerHTML = then.toString().match(time_pattern)[0];
        }, delay || 1000);
    
        return {cancel: function() { clearInterval(interval) }};
    }
    
    // Usage:
    var incrementing_time =
        increment_time_element(document.getElementById("updatetime"));
    
    // Then, if you want to cancel:
    incrementing_time.cancel();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

lets say i have a website that i am developing... the site may have
Lets say I've a website that lists Persons, and each Person has multiple properties,
Let's say that I have this website file root structure: frontend /home/username/public_html/ backend /home/username/public_html/admin/
I have 2 websites, lets say - example.com and example1.com example.com has a database
This is my first question on this wonderful website. Lets say I have a
I have a domain (lets say www.domain.com) and I want one section of that
Let's say I have a website that displays info about books. The info about
Here is what I need: Let's say I have a hotel rooms rental website
I need to develop an international website. Let's say I have a table called
Lets say you have a large, popular database-driven website. There are people on the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.