开发者

Javascript Date Sorting [duplicate]

开发者 https://www.devze.com 2023-01-29 15:07 出处:网络
This question already has answers here: Closed 12 years ago. Possible Duplicate: Javascript date sorting byconvert the string in to date format
This question already has answers here: Closed 12 years ago.

Possible Duplicate:

Javascript date sorting by convert the string in to date format

Hi,

2010-11-08 18:58:50
2010-11-09 17:49:42
2010-11-09 17:49:42
2010-11-24 19:44:51
2010-11-09 13:54:46
2010-11-23 20:06:29
2010-11-23 20:06:04
2010-11-15 17:51:37
.....................
..............
..........

like this i have n number of string formats .How can i convert these strings in to date format and sort accordingly...开发者_如何学编程.please

Thanks in advance, Joseph


Since you are using ISO date formats you can simply sort them lexically.

var dates = [
    '2010-11-08 18:58:50',
    '2010-11-09 17:49:42',
    // and so on...
];

dates.sort();

For more information on sorting: http://www.w3schools.com/jsref/jsref_sort.asp


i bet this one can help

how-can-i-convert-a-date-value-in-utc-format-to-a-date-object-in-javascript


The dates are already in a form that is suitable for sorting. So all you need to do is call array.sort().

0

精彩评论

暂无评论...
验证码 换一张
取 消