【问题标题】:Table sorting is not working for dates in ie9, firefox表格排序不适用于 ie9、firefox 中的日期
【发布时间】:2014-11-17 06:12:59
【问题描述】:

我有这样的日期格式 2009-04-17 07:17:46.0

为此,排序在 Chrome 中有效,但在 Firefox、Ie9 中无效。

表格排序器 V 2.0.5

【问题讨论】:

  • 这个问题解决了吗?我也有同样的问题。

标签: jquery jquery-plugins tablesorter


【解决方案1】:

试试这个iso 8601 date parser:

/*! ISO-8601 date parser
 * This parser will work with dates in ISO8601 format
 * 2013-02-18T18:18:44+00:00
 * Written by Sean Ellingham :https://github.com/seanellingham
 * See https://github.com/Mottie/tablesorter/issues/247
 */
var iso8601date = /^([0-9]{4})(-([0-9]{2})(-([0-9]{2})(T([0-9]{2}):([0-9]{2})(:([0-9]{2})(\.([0-9]+))?)?(Z|(([-+])([0-9]{2}):([0-9]{2})))?)?)?)?$/;
$.tablesorter.addParser({
    id : 'iso8601date',
    is : function(s) {
        return s.match(iso8601date);
    },
    format : function(s) {
        var result = s.match(iso8601date);
        if (result) {
            var date = new Date(result[1], 0, 1);
            if (result[3]) { date.setMonth(result[3] - 1); }
            if (result[5]) { date.setDate(result[5]); }
            if (result[7]) { date.setHours(result[7]); }
            if (result[8]) { date.setMinutes(result[8]); }
            if (result[10]) { date.setSeconds(result[10]); }
            if (result[12]) { date.setMilliseconds(Number('0.' + result[12]) * 1000); }
            return date;
        }
        return s;
    },
    type : 'numeric'
});

【讨论】:

    猜你喜欢
    • 2017-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-22
    • 2015-02-06
    • 1970-01-01
    • 2013-02-19
    相关资源
    最近更新 更多