1

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.

3
  • you shoud use the standart angular filter for date docs.angularjs.org/api/ng/filter/date Commented Feb 3, 2016 at 5:51
  • I see only a typo: StatrtTime Commented Feb 3, 2016 at 8:48
  • this is not working. Commented Feb 3, 2016 at 8:59

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

Comments

1

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');
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.