2

使用 jQuery tablesorter 插件。我想知道如何使它与完整格式的日期一起使用:

“2009年1月21日16:00”

问题是当该日期(字符串)已使用用户当前语言环境本地化时

“2009 年 21 月 21 日 16:00”

我必须为每个语言环境编写一个自定义排序器吗?

谢谢。

<table id="orders" class="sortable">
    <thead>
        <tr>
            <th>Da</th>
            <th>Al</th>
            <th class="right">Camere</th>
            <th class="right">Spesa dell'ordine</th>
        </tr>
    </thead>
    <tr>
        <td>gen 21, 2009 22:00</td>
        <td>gen 22, 2009 22:00</td>
        <td class="right">1</td>
        <td class="right">30.00€&lt;/td>
    </tr>
4

1 回答 1

2

Well, the Tablesorter plugin will detect that "gen 21, 2009' is a date column. It will then pass it to the javascript Date constructor to parse it; that might be the step that fails. (I don't know if the constructor accepts localized strings; you can test that by running this:

new Date("gen 21, 2009 16:00").getTime();

If it returns "NaN" (as it does on my en-US firefox), then you'll need a custom parser. If it returns 1232514000000 then you don't need to do anything.

Tablesorter will detect a column as "US long date" if it matches this regular expression:

/^[A-Za-z]{3,10}\.? [0-9]{1,2}, ([0-9]{4}|'?[0-9]{2}) (([0-2]?[0-9]:[0-5][0-9])|([0-1]?[0-9]:[0-5][0-9]\s(AM|PM)))$/

a.k.a:

  • 3 - 10 alphabetic characters (month)
  • an optional period
  • a space
  • 1 - 2 digits (day)
  • comma, then space
  • 4-digit year, or apostrophe followed by 2-digit year
  • optional 24 hour time, or 12-hour time followed by uppercase AM or PM.
于 2009-08-06T19:15:23.533 回答