Angular.js Service
HTML
<div ng-app="myApp">
<div ng-controller="farmController">
<div>{{ cTime | dateFormat }}
</div>
</div>
</div>
JavaScript
var myApp = angular.module('myApp', []);
myApp.controller("farmController",function($scope){
$scope.cTime = 1439396762286;
})
myApp.service('formatting', function() {
var getDateFormat = function(){
return 'medium'
};
return {
getDateFormat : getDateFormat
};
});
myApp.filter('dateFormat', function($filter, formatting) {
return function(date) {
return $filter['date'](date, formatting.getDateFormat())
}
})