以MMM d,yyyy格式对日期进行排序

时间:2016-12-06 08:39:45

标签: javascript angularjs

我有这样的对象,左

 {
Nov 17, 2016:Array[1]
Dec 1, 2016:Array[1]
Nov 22, 2016:Array[1]
Nov 23, 2016:Array[1]
Nov 21, 2016:Array[1]
}

我希望以相同的日期格式将其排序为降序 输出应该是......提前感谢。

{
 Dec 1, 2016:Array[1]
 Nov 23, 2016:Array[1]
 Nov 22, 2016:Array[1]
 Nov 21, 2016:Array[1]
 Nov 17, 2016:Array[1]
}

https://plnkr.co/edit/kZzxHDg1om7ylbGYeloe?p=preview plunker

1 个答案:

答案 0 :(得分:1)

你只需要把

  

ng-repeat =“data.messages中的消息| orderBy:'createdTime':true”

它将按 createdTime

的降序排序您的数据
<div class="panel panel-default"  ng-repeat="message in data.messages | orderBy:'createdTime':true">
   <div class="panel-heading" style="color:blue">{{ message.createdTime | date:'MMM d, yyyy' }}</div>
   <div class="panel-body" >
       <span  uib-tooltip="{{message.userName}}" tooltip-placement="top">{{ message.groupList[0].userName }}, {{ message.groupList[1].userName }}</span>
   </div>
</div>

检查

https://plnkr.co/edit/CbV3uQI8JoU2Wt0wFsSl?p=preview