我有数据列表,我想从最早到最晚过滤它们
包含数据的列表如下所示:
[{id: 73, startTime: 2022-12-13T15:30:57.244Z}, {id: 74, startTime: 2022-12-13T10:00:57.244Z}];
输出应如下所示:
[{id: 74, startTime: 2022-12-13T10:00:57.244Z}, {id: 73, startTime: 2022-12-13T15:30:57.244Z}];
我该怎么做?附:我正在使用国际
最佳答案
假设我们有这个列表:
List dateList = [
{"id": 73, "startTime": "2022-12-13T15:30:57.244Z"},
{"id": 74, "startTime": "2022-12-13T10:00:57.244Z"},
];
你可以像这样使用sort()
:
dateList.sort((a, b) => a["startTime"].compareTo(b["startTime"]));
结果:
[
{id: 74, startTime: 2022-12-13T10:00:57.244Z},
{id: 73, startTime: 2022-12-13T15:30:57.244Z}
]
关于flutter - 如何在flutter中过滤DateTime(intl)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74786405/