Last active
          August 29, 2015 14:04 
        
      - 
      
- 
        Save bodhiprice/7c33087d917e51c81a33 to your computer and use it in GitHub Desktop. 
    Working with dates and localStorage example
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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 | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
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.