Javascript DatePicker format year in 2 digits

谁说我不能喝 提交于 2020-04-17 07:20:21

问题


I'm using datepicker. The problem I'm having is that the year is giving me 4 digits.

$.datepicker.setDefaults({
    dateFormat: 'dd-mm-yy'
});

Shouldn't yy give me only 2 digits?

How do I get 2 digits on the year instead of 4?


回答1:


This is about JQuery. Docs: http://api.jqueryui.com/datepicker/

y - year (two digit)
yy - year (four digit)

So:

$.datepicker.setDefaults({
    dateFormat: 'dd-mm-y'
});



回答2:


Use single y

$.datepicker.setDefaults({
    dateFormat: 'dd-mm-y'
});

Source: https://api.jqueryui.com/datepicker/



来源:https://stackoverflow.com/questions/39034419/javascript-datepicker-format-year-in-2-digits

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!