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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2057157/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 12:40:25  来源:igfitidea点击:

how can i format jquery datepicker as "25-JAN-2009"

jqueryformatdatepicker

提问by leora

I would have thought this was:

我会认为这是:

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

for month, I get some number that I don't understnad where they are coming from?

一个月,我得到了一些我不了解它们来自哪里的数字?

回答by Sampson

According to the documentation, a single M is "Month name short" and "yy" is "Four Digit Year."

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

dd-M-yy

回答by Pekka

This is a case where looking into the documentationis most helpful:

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

*  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 

回答by Dominic Rodger

You want:

你要:

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

See the docs.

请参阅文档

The date format strings are somewhat non-standard:

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

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

d- 月中的某天(无前导零)
dd- 月中的某天(两位数)
o- 年中的某天(无前导零)
oo- 年中的某天(三位数)
D- 日名称短
DD- 日名称长
m- 一年中的月份(无前导零)
mm- 月份(两位数)
M- 月份名称短
MM- 月份名称长
y- 年份(两位数)
yy- 年份(四位数)
@- Unix 时间戳(自 01/01/1970 以来的毫秒)
'...'- 文字文本
''- 单引号
任何内容else - 文字

回答by Gabriele Petrioli

The correct way is dd-M-yy

正确的方法是 dd-M-yy

Alternatively you can use the monthNamesShortoption for custom names ..

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

回答by MaxiMus

If you are using AUI Datepicker / Datepicketselect components then dateFormat usage is a bit different.

如果您使用 AUI Datepicker / Datepicketselect 组件,则 dateFormat 的用法有点不同。

for eg: if you want to display 01-Jan-2014, you will have to use dateFormat:'%d-%b-%Y'

例如:如果要显示 01-Jan-2014,则必须使用 dateFormat:'%d-%b-%Y'

following is the documentation that explains different formats: http://alloyui.com/versions/1.5.x/api/classes/DataType.Date.html

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

My working code: (on Liferay with AUI)

我的工作代码:(在带有 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>