2016-12-13 5 views
1

jquery ui datepickerにバグがあります。私のフォーマットはmm/dd/yで、例えば年は1915年です。したがって、1915年2月7日は02/07/15です。この日付を選択してdatepickerを閉じると、Firebug Inspectで年がうまく保存されていることがわかります.1915年ですが、再びdatepickerを開くと、選択した年は2015年で、1915年ではありません。jQuery UI datepicker mm/dd/y形式年1915年を2015に変換しました

私はjquery-1.9.1とjquery-ui-1.11.4を使用します。 私はこのライブラリを使用しています:https://github.com/trentrichardson/jQuery-Timepicker-Addon

これを修正する方法については何か考えてください。

+0

datepickerの使い方のサンプルコードを入力してください。文字列と日付オブジェクトを使って作業している場合、これはうまくいくはずです。文字列を扱っている場合、JSが1915年対2015年であると判断する方法はありません。 – Twisty

答えて

1

私は問題と解決策を見つけました。

問題は、私のコードでsomwhereが "setYear"関数を使用していたことでした。よると:手助けしようとしているため

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

ありがとう:

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. 

は、このウェブサイトはまた、溶液を提案:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getYear私は、ことがわかりました。これが将来他の人にも役立つことを願っています。 setYear関数を使用しないでください。代わりにを使用してください。setFullYear

関連する問題