Skip to content

Instantly share code, notes, and snippets.

@bodhiprice
Last active August 29, 2015 14:04
Show Gist options
  • Save bodhiprice/7c33087d917e51c81a33 to your computer and use it in GitHub Desktop.
Save bodhiprice/7c33087d917e51c81a33 to your computer and use it in GitHub Desktop.
Working with dates and localStorage example
var d1 = new Date();
var d2 = new Date();
localStorage.d1 = d1; // add to localStorage
localStorage.d2 = d2;
d1 = Date.parse(localStorage.d1); // pull from localStorage and parse to date object
d2 = Date.parse(localStorage.d2);
console.log(d2 - d1); // milliseconds elapsed between the two times.
localStorage.clear(); // clear local storage
@bodhiprice
Copy link
Author

Useful if you want JavaScript to run after a set interval. For example, to run an animation only once per visit you might use this to make sure 24 hours has passed before running animation again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment