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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:59:00+00:00 2026-05-24T17:59:00+00:00

So as I have learned today, if I put a phone in sleep mode

  • 0

So as I have learned today, if I put a phone in sleep mode that is running a javascript timer function, it will become paused.

As I need a timer for a certain application – that needs to continue to record the time and display it, updating the innerHTML of an element ever second: how do you think I should go about getting this timer to work?

Thanks for the grand help!

  • 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-24T17:59:01+00:00Added an answer on May 24, 2026 at 5:59 pm
    var startTime;
    var timer;
    
    function displayTime() {
        var now = new Date();
        var timeDiff = new Date(now - startTime); // constructor uses UTC, so use UTC date functions from here on
        var hours = timeDiff.getUTCHours();
        var mins = (timeDiff.getUTCMinutes() < 10) ? '0' + timeDiff.getUTCMinutes() : timeDiff.getUTCMinutes();
        var secs = (timeDiff.getUTCSeconds() < 10) ? '0' + timeDiff.getUTCSeconds() : timeDiff.getUTCSeconds();
        document.getElementById('time').innerHTML = hours + ':' + mins + ':' + secs;
        if (hours >= 2) clearInterval(timer);
    }
    
    window.onload = function() {
        startTime = new Date();
        timer = setInterval(displayTime, 1000);
    }
    

    When the phone wakes and the app goes back to foreground, startTime should still be the original time when you started counting, so you just need to know the diff between now and then. It doesn’t need to update the display while asleep; it just needs to know the time since the original starting time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have learned that Python 3 is not backwards compatible. Will it not affect
I have been learning about Bitwise operations today and I learned that Not (~)
I learned today that NetBeans 6.5 should have an on-the-fly compilation of (single) Java
I have learned that we can't instantiate an abstract class. But today i tested
Today I think i might have learned something (not sure), i'm not really a
I have recently learned to create dynamic links via php, but my problem today
I have learned from various tutorial that If a client can reasonably be expected
I have learned that Windows uses UTF-16LE on x86/x64 systems. What about Linux? Which
I have an application that stores images in a database. Now I have learned
I learned today through this section of the MySQL documentation that prepared statements cannot

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.