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()
.
精彩评论