Question: $scope data convert to date format


$scope data convert to date format

Answers 3
Added at 2017-01-01 08:01

how to convert $scope data to date format?

{{book.take_time | date: 'HH:mm'}}

$http.get("../api/book.php").then(function(response) {
        $ =;

inside book have book_id, book_name, take_time
how to convert take_time to date format?

Answers to

$scope data convert to date format

nr: #1 dodano: 2017-01-01 08:01

Update: The input $ 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'}} 

$http.get("../api/book.php").then(function(response) {
      $ =;

      angular.forEach($, function(value, key) {

        var res = value.take_time.split(":");
        //Assuming time is in hh:mm:ss format
        var date = new Date();

        value.take_time = date;


See a sample of it working here:

nr: #2 dodano: 2017-01-01 08:01

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--

nr: #3 dodano: 2017-01-01 09:01

Use Moment.js to convert time format


or if you have array then

angular.forEach($,function(value,key){value.take_time = moment(value.take_time).format('HH:mm')});

below is link for that js

Source Show
◀ Wstecz