Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Format time in angular js filter

How can I reformat time 06:31:04 to display only hh:mm - 06:31

Have tried

$scope.date = '06:31:04';

<p ng-bind="date | date:'HH:mm'"></p>

but time not formatting

How should I make it, thanks

like image 692
AlexFF1 Avatar asked Jun 22 '15 20:06

AlexFF1


People also ask

Which AngularJS filter formats a date to a specified format?

AngularJS date Filter The date filter formats a date to a specified format.


1 Answers

The best solution was to write a filter

angular.module('foo', [])
.filter('formatTime', function ($filter) {
return function (time, format) {
    var parts = time.split(':');
    var date = new Date(0, 0, 0, parts[0], parts[1], parts[2]);
    return $filter('date')(date, format || 'h:mm');
};
});




{{ '06:31:04' | formatTime }}
like image 103
AlexFF1 Avatar answered Sep 18 '22 17:09

AlexFF1