how to convert $scope data to date format?
{{book.take_time | date: 'HH:mm'}}
$http.get("../api/book.php").then(function(response) {
$scope.book = response.data;
});
inside book have book_id, book_name, take_time
how to convert take_time to date format?
3 Answers 3
Update: The input $scope.book is actually an array of books. Pl refer authors comments.
This is a rather crude way of doing it, but you can try something like this:
<p data-ng-repeat="value in books">
{{value.take_time | date: 'shortTime'}}
</p>
$http.get("../api/book.php").then(function(response) {
$scope.book = response.data;
angular.forEach($scope.book, function(value, key) {
var res = value.take_time.split(":");
//Assuming time is in hh:mm:ss format
var date = new Date();
date.setMinutes(res[1]);
date.setHours(res[0]);
value.take_time = date;
});
});
See a sample of it working here: http://www.w3schools.com/code/tryit.asp?filename=FBB8M1JMPUX5
4 Comments
Use Moment.js to convert time format
moment($scope.data[0].take_time).format('HH:mm')
or if you have array then
angular.forEach($scope.data,function(value,key){value.take_time = moment(value.take_time).format('HH:mm')});
below is link for that js
Comments
According to your comment you can try for "shortTime" date format
'shortTime': equivalent to 'h:mm a' for en_US locale (e.g. 12:05 PM)
for details--https://docs.angularjs.org/api/ng/filter/date
var converted = book.take_time.substring(0,6)