Skip to content

Instantly share code, notes, and snippets.

@failpunk
Created June 21, 2013 18:41
Show Gist options
  • Save failpunk/5833353 to your computer and use it in GitHub Desktop.
Save failpunk/5833353 to your computer and use it in GitHub Desktop.
Simple Angular.js filter for using the moment.js library
angular.module('myFilters', []).filter('momentjs', function() {
return function(input, formatString) {
var m = moment(input)
, formatString = formatString || ''
, out = '';
if(m && m.isValid()) {
if(formatString == 'calendar') {
out = m.calendar();
} else {
out = m.format(formatString);
}
}
return out;
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment