Last active
          December 22, 2017 11:48 
        
      - 
      
- 
        Save pimatco/60b93d309737c061ebc2611ee98334cf to your computer and use it in GitHub Desktop. 
    Convert Date to Local Time using Momentjs library and Get Difference from one date to another in minutes, hours or days
  
        
  
    
      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
    
  
  
    
  | //returns a string | |
| convertToLocalTimeToString(hora){ | |
| hora = moment.utc(hora); | |
| hora = hora.local().format(); | |
| return hora; | |
| } | |
| //returns a moment obj - use to get difference | |
| convertToLocalTimeToObj(hora){ | |
| hora = moment.utc(hora); | |
| hora = hora.local(); | |
| return hora; | |
| } | |
| //value is a string that stands for 'minutes', 'hours' or 'days' | |
| getDiffNowAndThen(now, then, value){ | |
| let difference = now.diff(then, 'minutes'); | |
| return difference; | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment