当前位置:网站首页>String time sorting, sorting time format strings

String time sorting, sorting time format strings

2022-06-11 00:15:00 Uninstall engine

let arr = [
	{
    time: '2021/08/10 20:18'},
	{
    time: '2021/08/10 05:18'},
	{
    time: '2021/07/10 14:18'},
	{
    time: '2021/08/13 14:05'},
	{
    time: '2021/08/01 20:18'},
	{
    time: '2021/09/10 20:18'},
	{
    time: '2021/09/05 20:18'},
]
//  Arrange the array in ascending chronological order , That is, the latest time is displayed at the end ,  as follows :
arr = arr.sort( 
(a,b) => new Date(a.time).getTime() - new Date(b.time).getTime()
);

Use

Object.keys(dataSources).sort((a, b) => {
    
  return new Date(a).getTime() - new Date(b).getTime()
}).map(item => {
    
  obj[item] = dataSources[item]
});

 Insert picture description here

原网站

版权声明
本文为[Uninstall engine]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/162/202206102256514759.html