Extract time from datetime using Angular js

2019-09-13 03:56发布

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

2条回答
啃猪蹄的小仙女
2楼-- · 2019-09-13 04:39

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

查看更多
Animai°情兽
3楼-- · 2019-09-13 04:46

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); */
}
查看更多
登录 后发表回答