简体   繁体   中英

Setting default date format for datepicker?

I have a page where I keep track of various dates. So I end up using datepicker through jquery anywhere from 10-200 times. I want to set the default for all cases of datepicker to the 'yy-mm-dd' - but I can't seem to figure out how to set that?

I end up using datepicker through jquery anywhere from 10-200 times.

I'm assuming you're calling datepicker() separately for each input, probably by id . There's no need for that.

Use a class as a hook on your input:

<input class="my-datepicker">

Then call datepicker on elements with that class with your default configuration:

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

When you need a different configuration, use/assign a different class name.

You can also use setDefaults (probably what you're looking for):

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

Go to the file jquery.ui.datepicker.js .

function Datepicker()
{
     dateFormat: 'mm/dd/yy'
}

Change it to the format you prefer. It will change the format for your whole website.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM