javascript日期排序

问题描述:

可能重复:字符串格式
Javascript date sorting by convert the string in to date formatjavascript日期排序

嗨,

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 
..................... 
.............. 
.......... 

这样的,我有N多。如何我可以将这些字符串转换中日期格式和相应的排序....请

在此先感谢,约瑟夫

+0

_like this like n number of strings formats_:Where?怎么样? – Nivas 2010-12-06 11:02:45

由于您使用的ISO日期格式,你可以简单地按字面排序。

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

dates.sort(); 

欲了解更多有关排序:http://www.w3schools.com/jsref/jsref_sort.asp

的日期已经是一个形式,是适合排序。所以你只需要拨打array.sort()即可。