设置自定义日期格式

默认日期格式: “mm / dd / yy”

以下示例显示如何使用 dateFormat 选项在初始化中设置日期格式。

<input type="text" id="datepicker">
<script>
    $("#datepicker").datepicker({
        dateFormat: "yy-mm-dd"
    });
</script>

以下示例显示如何使用 dateFormat 选项初始化后设置日期格式。

<input type="text" id="datepicker">
<script>
    $("#datepicker").datepicker( "option", "dateFormat", "yy-mm-dd" );
</script>

你可以使用以下组合:

d - day of month (no leading zero)
dd - day of month (two digit)
o - day of the year (no leading zeros)
oo - day of the year (three digit)
D - day name short
DD - day name long
m - month of year (no leading zero)
mm - month of year (two digit)
M - month name short
MM - month name long
y - year (two digit)
yy - year (four digit)
@ - Unix timestamp (ms since 01/01/1970)
! - Windows ticks (100ns since 01/01/0001)
'...' - literal text
'' - single quote
anything else - literal text

或预定标准:

ATOM - 'yy-mm-dd' (Same as RFC 3339/ISO 8601)
COOKIE - 'D, dd M yy'
ISO_8601 - 'yy-mm-dd'
RFC_822 - 'D, d M y' (See RFC 822)
RFC_850 - 'DD, dd-M-y' (See RFC 850)
RFC_1036 - 'D, d M y' (See RFC 1036)
RFC_1123 - 'D, d M yy' (See RFC 1123)
RFC_2822 - 'D, d M yy' (See RFC 2822)
RSS - 'D, d M y' (Same as RFC 822)
TICKS - '!'
TIMESTAMP - '@'
W3C - 'yy-mm-dd' (Same as ISO 8601)

使用以下示例可以将默认日期格式应用于所有日期选择器:

<script>
    $.datepicker.setDefaults({
        dateFormat: "yy-mm-dd"
    });
</script>