Skip to content

Instantly share code, notes, and snippets.

@mehmetbebek
Created December 1, 2016 06:06
Show Gist options
  • Save mehmetbebek/247e5d306acdba2551f49366fab8eb83 to your computer and use it in GitHub Desktop.
Save mehmetbebek/247e5d306acdba2551f49366fab8eb83 to your computer and use it in GitHub Desktop.
Moment.js Minutes to Hour(HH:mm) format
.filter('formatMinuteToHour', function () {
return function (mins) {
/* if (mins >= 24 * 60 || mins < 0) {
throw new RangeError("Valid input should be greater than or equal to 0 and less than 1440.");
}
*/
var h = mins / 60 | 0,
m = mins % 60 | 0;
return moment().utc().hours(h).minutes(m).format("HH:mm");
}
})
$scope.formatMinuteToHour = function(mins){
return $filter('formatMinuteToHour')(mins);
};
@mehmetbebek
Copy link
Author

.filter('formatStringToDate', function () {
return function (date, oldDateFormat, newDateFormat) {
return moment(date, oldDateFormat).format(newDateFormat);
}
})
$scope.formatStringToDate = function (inputStr) {
return $filter('formatStringToDate')(inputStr, 'dd/MM/yyyy', 'D MMM YYYY');
};

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