Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Formatting out of a jQuery UI datepicker

I'm having a problem trying to format the output on the jQuery UI datepicker.

I want the dateformat to be the 'ISO 8601' format, like explained here:

http://jqueryui.com/demos/datepicker/#date-formats

This is what my code looks like:

$.datepicker.setDefaults($.datepicker.regional['nl']); $('.datepicker').datepicker('option', {dateFormat: 'yy-mm-dd' }); 
like image 205
Sam Vloeberghs Avatar asked Mar 21 '10 11:03

Sam Vloeberghs


People also ask

How can change date format in jQuery UI Datepicker?

inside the jQuery script code just paste the code. $( ". selector" ). datepicker({ dateFormat: 'yy-mm-dd' });

How do I change date picker format?

Do one of the following: For a text box control or a date picker control, ensure that the Data type list displays the appropriate data type, and then click Format. For an expression box control, ensure that the Format as list displays the appropriate data type, and then click Format.

How do I change Datepicker format from DD MM to YYYY?

var year = 2014; var month = 5; var day = 10; var realDate = new Date(year, month - 1, day); // months are 0-based! $('#MainContent_txtDataConsegna'). datepicker({ dateFormat: 'dd/mm/yyyy' }); // format to show $('#MainContent_txtDataConsegna'). datepicker('setDate', realDate);

How do I reinitialize Datepicker?

I would do it like this: $('#sv_pickup_date'). datepicker('destroy'). datepicker({ format: 'dd/mm/yyyy' , autoclose: true , startDate: '20/08/2018' , endDate: '24/08/2018' });


1 Answers

Your option setter format is just a bit off, try this:

$('.datepicker').datepicker('option', 'dateFormat', 'yy-mm-dd'); 

See the options pane on that page for how to set each one in this way

when doing it globally before creating a picker, do this:

$.datepicker.setDefaults($.datepicker.regional['nl']);  $.datepicker.setDefaults({ dateFormat: 'yy-mm-dd' }); //Later.. $('.datepicker').datepicker(); 

Also, make sure to include your regional file, or the $.datepicker.regional['nl'] doesn't mean anything, this needs to be included before trying to setDefaults to your regional: http://jquery-ui.googlecode.com/svn/trunk/ui/i18n/

like image 65
Nick Craver Avatar answered Sep 28 '22 05:09

Nick Craver