Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/428.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery UI日期选择器mm/dd/y格式1915年转换为2015年_Javascript_Jquery_Date_Jquery Ui_Datepicker - Fatal编程技术网

Javascript jQuery UI日期选择器mm/dd/y格式1915年转换为2015年

Javascript jQuery UI日期选择器mm/dd/y格式1915年转换为2015年,javascript,jquery,date,jquery-ui,datepicker,Javascript,Jquery,Date,Jquery Ui,Datepicker,我的jQueryUIDatePicker中有一个bug。我的格式是:mm/dd/y,例如年份是:1915年。因此,1915年2月7日将是:2015年2月7日。在我选择这个日期并关闭日期选择器之后,我可以通过Firebug Inspect看到年份保存得很好,是1915年,但是当我再次打开日期选择器时,选择的年份是2015年,而不是1915年 我正在使用jquery-1.9.1和jquery-ui-1.11.4。 我也在使用这个库: 有没有办法解决这个问题?我找到了问题和解决方案 问题是,在我的代码

我的jQueryUIDatePicker中有一个bug。我的格式是:mm/dd/y,例如年份是:1915年。因此,1915年2月7日将是:2015年2月7日。在我选择这个日期并关闭日期选择器之后,我可以通过Firebug Inspect看到年份保存得很好,是1915年,但是当我再次打开日期选择器时,选择的年份是2015年,而不是1915年

我正在使用jquery-1.9.1和jquery-ui-1.11.4。 我也在使用这个库:


有没有办法解决这个问题?

我找到了问题和解决方案

问题是,在我的代码中,有些地方我使用了“setYear”函数。根据:我发现:

For years greater than or equal to 2000, the value returned by getYear() is 100 or greater. For example, if the year is 2026, getYear() returns 126.
For years between and including 1900 and 1999, the value returned by getYear() is between 0 and 99. For example, if the year is 1976, getYear() returns 76.
For years less than 1900, the value returned by getYear() is less than 0. For example, if the year is 1800, getYear() returns -100.
该网站还提出了解决方案:

To take into account years before and after 2000, you should use getFullYear() instead of getYear() so that the year is specified in full.

谢谢你的帮助。我希望这也将有助于其他人在未来不要使用setYear函数,改用setFullYear

请提供一些使用日期选择器的示例代码。如果您使用的是日期对象,而不是字符串,这应该没问题。如果您使用的是字符串,JS无法确定这是1915年还是2015年。