Skip to content

Instantly share code, notes, and snippets.

@cakuki
Created June 10, 2015 12:38
Show Gist options
  • Save cakuki/d58ec01964821a6367fd to your computer and use it in GitHub Desktop.
Save cakuki/d58ec01964821a6367fd to your computer and use it in GitHub Desktop.
Angular.js ObjectId to Date filter
/**
* Extracts creation timestamp from ObjectId.
*
* Usage for default id mongoose objects in html:
* {{ object._id | idToDate | date:'medium' }}
*/
angular.module('idToDate').filter('idToDate', [function() {
return function idToDate (objectId) {
return new Date(parseInt(objectId.slice(0, 8), 16) * 1000);
};
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment