0

I need to extract the hour and minute from the datetime(eg:2013-09-03 05:02:04) using Angular js.I have done like this.

JSON Data:

{
    "status": "success",
    "data": [
        {
            "PriorityPassReservation": {
                "site_id": "8",
                "id": "235907",
                "priority_pass_schedule_id": "4",
                "member_id": null,
                "member_guid": "8-853414",
                "reservation_dt": "2013-09-05 19:00:00",
                "checkin_dt": null,
                "reminder_sent": "0",
                "created": "2013-09-03 05:02:04",
                "modified": "2013-09-03 05:02:04",
                "status": "booked"
            }
]
}

HTML:

    <tr ng-repeat="priority in priorityDetails.data">
     <td class="no">{{ $index +1 }}</td>

  <td class="priority_time">{{priority.PriorityPassReservation.reservation_dt| date:' hh:mm'}}</td>

  </tr>

But it does not give the actual result.Does anybody knows the solution?

NB: priority.PriorityPassReservation.reservation_dt is a json string

3
  • Have you tried angular.fromJson to convert it to a deserialized string? Commented Sep 5, 2013 at 11:26
  • @David Chase no..I didnt do like that.Updated my question Commented Sep 5, 2013 at 11:31
  • well your problem is because you already have a date and time the filter wont work on your value, try just using a string anything with a ":" will throw an unexpected token error Commented Sep 5, 2013 at 11:35

2 Answers 2

3

I think the issue might be related to the angular date filter supporting only ISO8601 compliant date string formats. You can simply convert your date string to a date object.

<td class="priority_time">
    {{getDateObject(priority.PriorityPassReservation.reservation_dt) | 
    date:' h:mm'}}
</td>

In your controller:

$scope.getDateObject = function(dt){
    /* convert to date object */
    /* return new Date(2013,8,3,5,2,4); */
}
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks Code Hater..Hope it will work,but how can i dynamically convert the date object
@Gopesh You can extract y, m, d, h, m, s by splitting your string and then passing them to the Date constructor.
Just for future reference, a commonly-used library for this task is moment.js. It can parse the date for you and much more!
0

Time - 05:02:04 (0-24 format). Try to use 'hh:mm'. Or use time format Oct 29, 2010 8:40:23 AM (with AM).

1 Comment

Thanks for your reply.but it doesnot work..Actually priority.PriorityPassReservation.reservation_dt is a json string

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.