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 5988241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:55:52+00:00 2026-05-22T22:55:52+00:00

I want to be able to add a specified time to a javascript clock

  • 0

I want to be able to add a specified time to a javascript clock and have it keep updating. I have managed to chuck the below together.

    function leadTimer(leadTime) 
    {
      var d1 = new Date (),
      d2 = new Date ( d1 );
      d2.setMinutes ( d1.getMinutes() + leadTime );
      currentHours = d2.getHours();
      currentMins = d2.getMinutes();
      // Choose either "AM" or "PM" as appropriate
      var timeOfDay = ( currentHours < 12 ) ? "AM" : "PM";
      // Convert the hours component to 12-hour format if needed
      currentHours = ( currentHours > 12 ) ? currentHours - 12 : currentHours;
      // Convert an hours component of "0" to "12"
      currentHours = ( currentHours == 0 ) ? 12 : currentHours;
      if (currentMins<=9) { currentMins="0"+currentMins; }
      if (currentHours<10) { currentHours="0"+currentHours; }
      $("#result").empty();
      $("#result").html(currentHours + ":" + currentMins + " " + timeOfDay)
      setInterval('leadTimer(leadTime)',10000)
}

I figured that the setInterval would just use the current value for leadTime but I just get an error saying leadTime is undefined.

Ultimately I would like to be able to call on this to keep a clock ticking over depending on what the user selects.

  • 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-05-22T22:55:53+00:00Added an answer on May 22, 2026 at 10:55 pm

    You’ve almost got it; the preferred way to use setInterval is to give it a function as the first argument, so try changing your last line to this instead:

    setInterval(function(){leadTimer(leadTime)}, 10000);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to add a breakpoint condition to my code in VC++ Express 2005,
Scenario: I have several services that I want to be discovered by different clients.
I want to be able to launch a specific page of the home screen
C# 3.0 Extension methods add extensions to the base Type making calling that method
I am working on implementing a function that would execute another function a few
So here's my problem: I cannot seem to be able to configure CruiseControl.NET to
I'm trying to add another restriction on a method within a generic class. Is
I wanted to avoid the switch statement. I have over 30 document types. There
I have an app that loads records from a binary log file and displays
I'm building an app that needs to be able to extend facebook graph data.

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.