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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:50:46+00:00 2026-06-01T17:50:46+00:00

FOR THE MODERATORS!! I CREATED THIS QUESTION ON stackapps AFTER A RESEARCH INTO THE

  • 0

FOR THE MODERATORS!!
I CREATED THIS QUESTION ON stackapps AFTER A RESEARCH INTO THE STACK SECTIONS.
DO I NEED TO DELETE THIS ONE?

Hi I’m creating a simple HTML5 app which uses a timeout().
The basic function of the APP is:
you select an Item and a timeout() starts. It works properly but if I close the application the timer will stop of course.
I’m trying to store it in localStorage but it does not work for what I need.

here is my code

get current date

var current = new Date();

check if localStorage is empty or not. If not, it calculate the difference in milliseconds beetwen the stored date and the current date.

function update() {
  if (localStorage.time != undefined){
  var diff = current - localStorage.time;
   alert (diff)
}

update();

here the function save for the date to be stored and it check the difference beetwen the two dates.

function save() {
  localStorage.time = new Date();
  click_time = localStorage.time;
  var diff =  click_time - current;
   alert (diff);
   }

clear the localStorage

   function clear() {
   localStorage.clear();
   }

$(document).ready(function() {
$('input#save').click(function(){
  save();
});
$('input#clear').click(function(){
  clear();
});
});


<input type="submit" value="click me!" id="save"/>
<input type="submit" value="clear" id="clear"/>

But I just get NaN!!The problem is how do i need to store the date in the localStorage and how can i get it as a date?

Thanks in advance.

  • 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-01T17:50:48+00:00Added an answer on June 1, 2026 at 5:50 pm

    Replace all new Date(); with new Date().getTime();

    The differences between new Date().getTime()’s will be in milliseconds.

    And just to elaborate:

    Using new Date() will return a string like this “Fri Mar 30 2012 12:02:33 GMT-0400 (EDT).” So when you try to perform subtraction between two of these strings, you get NaN.

    new Date().getTime() will return an integer like this 1333123359919. This is in milliseconds from January 1st, 1970 (or something like that). So the difference between two of these will give you the number of milliseconds between the two calls, which is what you want.

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

Sidebar

Related Questions

Pls don't include subjective thoughts, or moderators will close this question like they closed
This question was initially posted on Google Moderator for the AndroidDev Office Hours Hangout
I have marked this question as community wiki, so no rep points are thrown
I have one specific view created in my DB(joins about 5-6 tables with a
this is not a question about a specific programming problem, it's about examining different
i need to add video streaming capabilities to drupal. I need this functions: Some
This question requires a bit of context before it makes sense so I'll just
After registering on my site I can make people moderators which just changes 1
I'm trying to create a method to run after any new user is created.
For clarification, I am essentially re-writing this question. I have a table, as defined

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.