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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T01:28:12+00:00 2026-06-17T01:28:12+00:00

I want to have a timer in my website like a digital clock. It

  • 0

I want to have a timer in my website like a digital clock. It will have a date and a time in it. I have this following code to do it:

var clockID = 0;

function UpdateClock() {
   if(clockID) {
      clearTimeout(clockID);
      clockID  = 0;
   }

    var tDate = new Date();
    var in_hours = tDate.getHours()
    var in_minutes=tDate.getMinutes();
    var in_seconds= tDate.getSeconds();

    if(in_minutes < 10)
        in_minutes = '0'+in_minutes;
    if(in_seconds<10)   
        in_seconds = '0'+in_seconds;
    if(in_hours<10) 
        in_hours = '0'+in_hours;

   document.getElementById('theTime').innerHTML = "" 
                   + in_hours + ":" 
                   + in_minutes + ":" 
                   + in_seconds;

   clockID = setTimeout("UpdateClock()", 1000);
}
function StartClock() {
   clockID = setTimeout("UpdateClock()", 500);
}

function KillClock() {
   if(clockID) {
      clearTimeout(clockID);
      clockID  = 0;
   }
}

But this code is displaying the current computer time so the time doesn’t fit with my timezone. What else do i need to add in my code so that it will display date and time according to my timezone? If the date is on DST, it will show the exact time in DST too.

  • 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-17T01:28:13+00:00Added an answer on June 17, 2026 at 1:28 am

    If you need to use JS only, have a look at

    add or subtract timezone difference to javascript Date

    For example DEMO

    var clockID;
    var yourTimeZoneFrom = -7.00; //time zone value where you are at
    
    var d = new Date();  
    //get the timezone offset from local time in minutes
    var tzDifference = yourTimeZoneFrom * 60 + d.getTimezoneOffset();
    //convert the offset to milliseconds
    var offset = tzDifference * 60 * 1000;
    
    function UpdateClock() {
        var tDate = new Date(new Date().getTime()+offset);
        var in_hours = tDate.getHours()
        var in_minutes=tDate.getMinutes();
        var in_seconds= tDate.getSeconds();
    
        if(in_minutes < 10)
            in_minutes = '0'+in_minutes;
        if(in_seconds<10)   
            in_seconds = '0'+in_seconds;
        if(in_hours<10) 
            in_hours = '0'+in_hours;
    
       document.getElementById('theTime').innerHTML = "" 
                       + in_hours + ":" 
                       + in_minutes + ":" 
                       + in_seconds;
    
    }
    function StartClock() {
       clockID = setInterval(UpdateClock, 500);
    }
    
    function KillClock() {
      clearTimeout(clockID);
    }
    window.onload=function() {
      StartClock();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have time in NSString like 15:15 I want to covert this NSString time
I have this code: function getTime(zone, success) { var url = 'http://json-time.appspot.com/time.json?tz=' + zone,
I want to have a clock showing current time and refreshes every second. The
I really didn't want to have to waste people's time and ask this, but
Let's assume i have a website like quora where i want to count how
I have a php website like this: .---------------------. |title stats | | | |generate&display
I've a live website, where i want to have an option like PHP profiler
I want to support the following scenarios on my ASP.NET MVC website: First time
I have a simple quiz application and I want display a nice timer /
I have created a very simple sharepoint timer job. All i want it to

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.