我是靠谱客的博主 勤劳日记本,这篇文章主要介绍js 时间排序,现在分享给大家,希望可以做个参考。

Date.parse()的参数,传入的时间就行

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <script> // let arr = ['2020-10-11','2022-10-11','2020-12-11','2021-11-11'] // function sortDownDate(a, b) { // return Date.parse(a) - Date.parse(b); // } // function sortUpDate(a, b) { // return Date.parse(b) - Date.parse(a); // } // console.log(arr.sort(sortDownDate)); // console.log(arr.sort(sortUpDate)); //--------------------------- let arr = [ { time:'2020-11-12' }, { time:'2020-11-13' }, { time:'2020-11-11' }, ] function sortDownDate(a, b) { return Date.parse(a.time) - Date.parse(b.time); } function sortUpDate(a, b) { return Date.parse(b.time) - Date.parse(a.time); } console.log(arr.sort(sortDownDate)); console.log(arr.sort(sortUpDate)); </script> </body> </html>

最后

以上就是勤劳日记本最近收集整理的关于js 时间排序的全部内容,更多相关js内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(80)

评论列表共有 0 条评论

立即
投稿
返回
顶部