我有一个时间戳(长)列表,其中我必须根据时间或添加的列表对列表进行排序。
我已经尝试和搜索过,但它现在可以工作了。
Collections.sort(vehicles, new Comparator<VehicleListModel.Vehicle>() {
@Override
public int compare(VehicleListModel.Vehicle o1, VehicleListModel.Vehicle o2) {
try {
DateFormat format = new SimpleDateFormat("MM-dd-yyyy hh:mm:ss");
return format.parse(o1.getCreated()).compareTo(format.parse(o2.getCreated()));
} catch (Exception e) {
e.printStackTrace();
return 0;
}
}
});
customerListAdapter.notifyDataSetChanged();
Run Code Online (Sandbox Code Playgroud)
它不起作用然后我尝试了
这个但它Date(timeStamp)已被弃用
请帮忙