Sameer Khan
Sameer Khan

Reputation: 147

How to extract time from json date string using AngularJS?

I want to extract a formatted time string from an incoming json data string but it is necessary to use moment.js in AngularJS to do this?

HTML Code:

<div  ng-repeat="event in events | limitTo:1">
    <div class="row spot">
        <span class="orange">When</span><br>
        <span class="large-font">{{event.Date}}</span> <span>{{moment(event.StatrtTime).format('hh:mm:ss a')}}</span><br>
            <span class="orange">Where</span>
    </div>

Incoming JSON:

events{
  "name":"Party",
   "StartTime":"2/19/2016 7:30:00 AM"
}

But this is not working.

Upvotes: 1

Views: 1119

Answers (2)

Vince
Vince

Reputation: 691

You could call a function that is in your controller which returns the time using momentjs.

Assuming your working with controllers

From the view

{{formatTime(time}}

In the controller

function formatTime(time) {
   var momentTime = moment(time);
   return momentTime.format('hh:mm');
}

Upvotes: 1

rkalita
rkalita

Reputation: 575

You should use standart filter for date in angular {{event.StatrtTime | 'hh:mm:ss a'}} instead of moment()

Upvotes: 2

Related Questions