Skip to content

Instantly share code, notes, and snippets.

@pimatco
Last active December 22, 2017 11:48
Show Gist options
  • Save pimatco/60b93d309737c061ebc2611ee98334cf to your computer and use it in GitHub Desktop.
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
//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