小编K R*_*Roy的帖子

如何对时间戳列表进行排序?

我有一个时间戳(长)列表,其中我必须根据时间或添加的列表对列表进行排序。

我已经尝试和搜索过,但它现在可以工作了。

 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)已被弃用

请帮忙

java sorting android timestamp date

1
推荐指数
1
解决办法
3万
查看次数

标签 统计

android ×1

date ×1

java ×1

sorting ×1

timestamp ×1