I am trying to sort a two-dimensional array by a timestamp column Descending. This collumn (index 11) is in the format: ‘yyyy-MM-dd HH:mm:ss’. I have tried multiple things. According to the topics I’ve read, this code should work:
List.sort(function(x, y){
return Date.parse(y[11]) - Date.parse(x[11]);
});
Thank you in advance!
That will work on up-to-date browsers that support the only-recently-defined input format for
Date.parse(prior to ES5, it was just “parse whateverDate#toStringspits out”).Although never spec’d, older browsers will support it with
/rather than-in the date, so:Always test on your target browsers, of course, because again this was never specified.
For example, on IE8 and earlier:
…is
NaN, but:…is
1338556937000.