For use in a controller, you can do something like this:
myApp.controller('TimestampCtrl', ['$scope', function($scope) {
$scope.toTimestamp = function(date) {
var dateSplitted = date.split('-');
var formattedDate = dateSplitted[1]+'/'+dateSplitted[0]+'/'+dateSplitted[2];
return new Date(formattedDate).getTime();
};
}]);
And can be used as follows:
<div ng-controller="TimestampCtrl">
The timestamp of <input ng-model="date"> is {{ toTimestamp(date) }}
</div>
source
share