格式化 jQuery UI 日期选择器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2486854/
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
Formatting out of a jQuery UI datepicker
提问by Sam Vloeberghs
I'm having a problem trying to format the output on the jQuery UI datepicker.
我在尝试格式化 jQuery UI 日期选择器上的输出时遇到问题。
I want the dateformat to be the 'ISO 8601' format, like explained here:
我希望日期格式为“ISO 8601”格式,如下所述:
http://jqueryui.com/demos/datepicker/#date-formats
http://jqueryui.com/demos/datepicker/#date-formats
This is what my code looks like:
这是我的代码的样子:
$.datepicker.setDefaults($.datepicker.regional['nl']);
$('.datepicker').datepicker('option', {dateFormat: 'yy-mm-dd' });
回答by Nick Craver
Your option setter format is just a bit off, try this:
你的选项设置器格式有点不对,试试这个:
$('.datepicker').datepicker('option', 'dateFormat', 'yy-mm-dd');
See the options pane on that page for how to set each one in this way
when doing it globally before creating a picker, do this:
在创建选择器之前全局执行此操作时,请执行以下操作:
$.datepicker.setDefaults($.datepicker.regional['nl']);
$.datepicker.setDefaults({ dateFormat: 'yy-mm-dd' });
//Later..
$('.datepicker').datepicker();
Also, make sure to include your regional file, or the $.datepicker.regional['nl']
doesn't mean anything, this needs to be included before trying to setDefaults to your regional: http://jquery-ui.googlecode.com/svn/trunk/ui/i18n/
另外,请确保包含您的区域文件,否则这$.datepicker.regional['nl']
并不意味着任何内容,这需要在尝试将默认值设置为您的区域之前包含:http: //jquery-ui.googlecode.com/svn/trunk/ui/i18n /
回答by jmadsen
$( "#end_date" ).datepicker({ dateFormat: 'yy-mm-dd' });
is what works for me
对我有用
回答by Ekonoval
You can also use a shorter way:
您还可以使用更短的方式:
$.datepicker.setDefaults(jQuery.extend( $.datepicker.regional['nl'], { dateFormat: 'yy-mm-dd' } ));