JQuery UI Datepicker日期格式问题与初始值
我需要将日期选择器的初始日期设置为2010年3月20日的mm-dd-yyyyy格式。
我已经做了这个
I need to set the initial date for the date picker to 03/20/2010 in mm-dd-yyyyy format. I have done this
<input id='datepicker' type='text' value='20/03/2010' />
但是,我的问题是点击字段日期选择器填充今天的日期,并且没有选择日期,并选择日期值
But my problem is on clicking the field date picker populates with today's date as highlighed and no date selected, and up on selecting date value
但是,当我更改输入字段时,如下所示
But when i change my input field like one below
<input id='datepicker' type='text' value='03/20/2010' />
日期选择器正在填充3月20日,因为选中的日期和当前日期突出显示。但是所有的都是'mm-dd-yyyy'格式!
Date picker is populating March 20 as selected date and current date highlighted. But all in 'mm-dd-yyyy' format!
我想以'dd-mm-yyyy'格式显示所有日期。我如何解决这个问题?
I want show all dates in 'dd-mm-yyyy' format. How can I solve this?
我尝试了一些下面的选项和组合,但是没有一个解决了我的问题
I tried some of the options and combinations below, but none of them solved my problem
$("#datepicker").datepicker();
$("#datepicker").datepick({dateFormat: 'mm/dd/yyyy'});
$("#datepicker").formatDate('dd/mm/yy');
$('#datepicker').datepicker("setDate", new Date($("#datepicker").val()) );
更新:
不幸的是我不能直接通过javascript sice设置日期值20更改并存储在PHP变量中。我需要从输入字段本身获取默认值。
Update: Unfortunately i cant set Date value march 20 directly via javascript sice it is dynamically changing and is stored in a PHP variable. I need to get the default value from input field itself.
$('#datepicker').datepicker('option', 'dateFormat', 'dd-mm-yy');
年份指定为 y
2位数和 yy
4位数字,如 here 。
Year is specified as y
for 2 digits and yy
for 4 digits, as stated here.