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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:21:19+00:00 2026-06-01T15:21:19+00:00

I have a webpage that, when you click start patrolling, starts counting the time

  • 0

I have a webpage that, when you click start patrolling, starts counting the time since you clicked the button. Because I need to store this on the server (ASP.NET) and because I want to resume the count when they reload the page, I get two variables from the server. The first variable is the server time they clicked the start patrolling button. The second variable is the offset of the local time from the server time so we are 100% exact on the amount of time and it isn’t off because of the local time. The following code works but the hours are WAY off. Currently the local time is 19:53 and if this function runs it starts at “18:00:00” and then goes up “18:00:01”, “18:00:02” etc… If the local time was 20:53 it would be “19:00:00”. Why is this function doing this and how can I correct this?

patroltimeCurrentTimeoffset is the returned offset value (EG: -729)

patroltimeStart is the date and time the on the server that the user started patrolling (EG: April 10, 2012 20:01:13)

function UpdatePatrolTime() {
        var patroltimeCurrentTime = new Date();

        patroltimeCurrentTime.setTime(patroltimeCurrentTime.getTime() + patroltimeCurrentTimeoffset);

        var patroltimeStarted = new Date(patroltimeStart);
        var CompareDateTime = new Date((patroltimeCurrentTime.getTime()-patroltimeStarted.getTime()));

        currentHours = CompareDateTime.getHours();
        currentMinutes = CompareDateTime.getMinutes();
        currentSeconds = CompareDateTime.getSeconds();

        currentHours = (currentHours < 10 ? "0" : "") + currentHours;
        currentMinutes = (currentMinutes < 10 ? "0" : "") + currentMinutes;
        currentSeconds = (currentSeconds < 10 ? "0" : "") + currentSeconds;

        var currentTimeString = currentHours + ":" + currentMinutes + ":" + currentSeconds

        document.getElementById("patroltime").firstChild.nodeValue = currentTimeString;
    }

And the <span> control:

<span id="patroltime">00:00:00</span>
  • 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-01T15:21:21+00:00Added an answer on June 1, 2026 at 3:21 pm

    I found a solution from “How to get the time elapsed from a json date?” but if anybody is able to figure out why my solution above doesn’t work (so I can award someone points for explaining for me and possibly others) I will award them the points. My solution was to change the following code:

        var patroltimeStarted = new Date(patroltimeStart);
        var CompareDateTime = new Date((patroltimeCurrentTime.getTime()-patroltimeStarted.getTime()));
    
        currentHours = CompareDateTime.getHours();
        currentMinutes = CompareDateTime.getMinutes();
        currentSeconds = CompareDateTime.getSeconds();
    

    to

        var patroltimeStarted = new Date(patroltimeStart);
        var diff = (patroltimeCurrentTime-patroltimeStarted);
    
        currentHours = Math.floor(diff / 3600000);
        currentMinutes = Math.floor((diff % 3600000) / 60000);
        currentSeconds = Math.floor(((diff % 3600000) % 60000) / 1000);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a webpage that is taking way too long and need to optimize
I have a webpage that displays a very large list of data. Since this
I have a webpage that contains a form, and i need to refresh the
I have a webpage that pulls information from a database, converts it to .csv
I have a webpage that implements a set of tabs each showing different content.
I have a webpage that redirects to another webpage like this: http://www.myOtherServer.com/Sponsor.php?RedirectPage=http://mylink.com/whereIwasgoingtogo.html Then the
I have a webpage that I don't have the ability to change the underlying
I have a webpage that activates a print job on a printer. This works
I have a webpage that displays a calendar, and I want to change the
I have this webpage that I want to post to my profile in FB.

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.