本文介绍了采用了棱角分明的js提取日期时间时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要提取日期时间的小时和分钟(例如:2013年9月3日5时02分04秒)。采用了棱角分明js.I都做过这样的

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数据:

{
    "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>

但它没有给出实际的result.Does任何人知道该如何解决?

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

注: priority.PriorityPassReservation.reservation_dt 是一个JSON字符串

NB: priority.PriorityPassReservation.reservation_dt is a json string

推荐答案

我认为这个问题可能与角日期过滤器,只支持ISO8601的日期字符串格式。
您可以将日期字符串简单地转换为日期对象。

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>

在你的控制器:

$scope.getDateObject = function(dt){
    /* convert to date object */
    /* return new Date(2013,8,3,5,2,4); */
}

这篇关于采用了棱角分明的js提取日期时间时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 09:25
查看更多