如何排序unix纪元时间数组

AngularJS – how to sort array of unix epoch time

本文关键字:unix 纪元 时间 数组 排序 何排序      更新时间:2023-09-26

我正在获得unix epoch时间的数组,我正在转换为GMT字符串。我想对数组排序,我该怎么做呢?

for(var i in data.results) {
    var date = new Date(data.results[i].lastModifiedAt*1000);
    var day = date.toGMTString();
    $scope.day[i] = day;
}

既然您将问题标记为有角度的,那么您可以将ng-repeatorderBy一起使用。比如:

$scope.results = data.results.map(function(result) {
  result.day = new Date(result.lastModifiedAt*1000).toGMTString()
  return result;
}

在你的html中:

<div ng-repeat="result in results | orderBy:'day':true track by $index"></div>

您将不必使用sort