我使用下面的腳本用於排序和filteriing表表達
http://javascripttoolbox.com/libsource.php/table/source/table.js經常在歐洲格式排序時間(DD-MM-YYYY)
我日期格式爲:dd-MM-yyyy。
腳本已建成三個正則表達式功能排序日期:
sort.date.formats = [
// YY[YY]-MM-DD
{
re: /(\d{2,4})-(\d{1,2})-(\d{1,2})/,
f: function (x) {
return (new Date(sort.date.fixYear(x[1]), +x[2], +x[3])).getTime();
}
}
// MM/DD/YY[YY] or MM-DD-YY[YY]
,
{
re: /(\d{1,2})[\/-](\d{1,2})[\/-](\d{2,4})/,
f: function (x) {
return (new Date(sort.date.fixYear(x[3]), +x[1], +x[2])).getTime();
}
}
// Any catch-all format that new Date() can handle. This is not reliable except for long formats, for example: 31 Jan 2000 01:23:45 GMT
,
{
re: /(.*\d{4}.*\d+:\d+\d+.*)/,
f: function (x) {
var d = new Date(x[1]);
if (d) {
return d.getTime();
}
}
}];
所以現在的問題是,如何在格式正則表達式的日期DD-MM-YYYY是什麼樣子?
我創建了一個的jsfiddle這裏:
請讓我知道,如果你的解決方案適用於該截止日期列!
第二個一定會支持DD-MM-YYYY也一樣,如果你在日期構造周圍交換匹配。 – lonesomeday
只要給出日期'01-02-2013',就不可能知道它是格式爲「DD-MM-YYYY」還是「MM-DD-YYYY」。 –
看看我的jsFiddle在截止日期欄 - 我無法讓它正常工作 – Kenci