var allMyApp = [
{"startDate": "2018-07-07 12:30:00",'name':'aa'},
{"startDate": "2018-07-09 12:30:00",'name':'bb'},
{"startDate": "2018-07-05 12:30:00",'name':'cc'},
{"startDate": "2018-07-01 12:30:00",'name':'dd'}
];
var newArr = [];
for(var p = 0; p < allMyApp.length; p++){
newStartDate = (allMyApp[p].startDate).replace(new RegExp("-", "gm"), "/");
startHaoMiao = (new Date(newStartDate)).getTime(); //得到毫秒数
newArr.push(allMyApp[p])
newArr[p].timeStartApp = startHaoMiao;
}
console.log(newArr);
var arr = newArr.sort(sortDate); //arr就是最终的排序后的数组
console.log(arr);
function sortDate(a,b){
return a.timeStartApp-b.timeStartApp
}
转载于:https://www.cnblogs.com/qing619/p/9284249.html