Answers to $scope data convert to date format ( 3 )

  1. 2017-01-01 08:01

    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

  2. 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--https://docs.angularjs.org/api/ng/filter/date

  3. 2017-01-01 09:01

    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

    http://momentjs.com/

Leave a reply to - $scope data convert to date format

◀ Go back