如何将jquery datepicker格式化为“25-JAN-2009”

时间:2010-01-13 14:08:30

标签: jquery format datepicker

我原以为这是:

.datepicker({ dateFormat: 'dd-mmm-yyyy' });

一个月,我得到一些我不知道他们来自哪里的号码?

5 个答案:

答案 0 :(得分:42)

根据the documentation,单个M是“月份名称短”,“yy”是“四位数年份”。

dd-M-yy

答案 1 :(得分:19)

在这种情况下,查看documentation最有帮助:

*  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)
* '...' - literal text
* '' - single quote
* anything else - literal text 

答案 2 :(得分:11)

你想:

$('.selector').datepicker({ dateFormat: 'dd-M-yy' });

请参阅docs

日期格式字符串有点不标准:

d - 月中的一天(没有前导零)
dd - 每月的一天(两位数)
o - 一年中的某一天(没有前导零)
oo - 一年中的某一天(三位数)
D - 天名短 DD - 天名长 m - 一年中的月份(无前导零)
mm - 一年中的一个月(两位数)
M - 月份名称短 MM - 月份名称长 y - 年(两位数)
yy - 年(四位数)
@ - Unix时间戳(自1970年1月1日起的ms)
'...' - 字面文字
'' - 单引号
其他 - 文字文本

答案 3 :(得分:3)

正确的方法是dd-M-yy

或者,您可以使用 monthNamesShort 选项进行自定义名称..

答案 4 :(得分:0)

如果您使用的是AUI Datepicker / Datepicketselect组件,则dateFormat的使用情况会略有不同。

例如:如果您想显示2014年1月1日,则必须使用 dateFormat:'%d-%b-%Y'

以下是解释不同格式的文档: http://alloyui.com/versions/1.5.x/api/classes/DataType.Date.html

我的工作代码:(在带有AUI的Liferay上)

<div id="myDatepicker"></div>
  <input type="text" name="myDateValue" id="myDateValue" size="9" /> 

<aui:script>
  AUI().use('aui-datepicker', function(A) {
     new A.DatePickerSelect(
       {
         appendOrder: ['d', 'm', 'y'],
        calendar: {
        dateFormat: '%d-%b-%Y'
    },
    boundingBox: '#myDatepicker',
    trigger: '#myDateValue'
  }
).render();
}
);
</aui:script>