2013-09-05 47 views
0

我需要使用Angular js.从日期时间(例如:2013-09-03 05:02:04)中提取小时和分钟。我做了这样的事情。使用Angular js从日期时间中提取时间

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有人知道该如何解决?

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

+0

你试过angular.fromJson将其转换为反序列化字符串? –

+0

@David Chase no ..我没有那样做。更新我的问题 – Gopesh

+0

以及你的问题是因为你已经有一个日期和时间过滤器不会对你的价值工作,只是使用一个字符串任何与“:”将抛出一个意外的令牌错误 –

回答

3

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

<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); */ 
} 
+0

感谢CodeHater..Hope它将工作,但我怎样才能动态地转换日期对象 – Gopesh

+0

@Gopesh你可以通过分割字符串然后将它们传递给'Date'构造函数来提取y,m,d,h,m,s。 – AlwaysALearner

+0

完成..谢谢。它节省了我的时间... – Gopesh

0

时间 - 5时02分04秒(0-24格式)。尝试使用'hh:mm'。或者使用时间格式Oct 29,2010 8:40:23 AM(与AM)。

+0

感谢您的reply.but它doesnot工作..其实priority.PriorityPassReservation.reservation_dt是一个json字符串 – Gopesh