var rows = [
{ "title": "第一条title", "time": "2008/08/27 05:30:45", "data": "这是数据" },
{ "title": "第二条title", "time": "2015/12/07 18:01:29", "data": "这是数据" },
{ "title": "第三条title", "time": "2011/09/14 22:56:17", "data": "这是数据" }
];
//降序将匿名函数参数a, b互换就行
rows.sort(function (a, b) {
return new Date(a.time).getTime() - new Date(b.time).getTime()
});
console.log(rows)
注:如果时间从大到小排列
rows.sort(function (a, b) {
return new Date(b.time).getTime()-new Date(a.time).getTime()
});
网友评论