Unable to change date format for given date - jquery datepicker

I want to change the date format of the set date to "dd.mm.yy"!

For me, this should work as in my code, but the installation date will show "11/19/2011" instead of "11/19/2011"

When I select a date, the format is correct!

<script type="text/javascript"> $(function() { $("#datepicker").datepicker(); $('#datepicker').datepicker({ dateFormat: 'dd.mm.yy' }); $('#datepicker').datepicker("setDate", "+3"); }); /* German initialisation for the jQuery UI date picker plugin. */ jQuery(function($){ $.datepicker.regional['de'] = { closeText: 'schließen', prevText: '&#x3c;zurück', nextText: 'Vor&#x3e;', currentText: 'heute', monthNames: ['Januar','Februar','März','April','Mai','Juni', 'Juli','August','September','Oktober','November','Dezember'], monthNamesShort: ['Jan','Feb','Mär','Apr','Mai','Jun', 'Jul','Aug','Sep','Okt','Nov','Dez'], dayNames: ['Sonntag','Montag','Dienstag','Mittwoch','Donnerstag','Freitag','Samstag'], dayNamesShort: ['So','Mo','Di','Mi','Do','Fr','Sa'], dayNamesMin: ['So','Mo','Di','Mi','Do','Fr','Sa'], weekHeader: 'Wo', dateFormat: 'dd.mm.yy', firstDay: 1, isRTL: false, showMonthAfterYear: false, yearSuffix: ''}; $.datepicker.setDefaults($.datepicker.regional['de']); }); </script> 
+3
source share
3 answers

I get it!

in this line

 $("#datepicker").datepicker(); 

The date picker will be initialized! therefore, the default date format is used!

which means that the format must be defined directly in the initialization, for example

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

or after initialization through setters

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

both options work!

+5
source

' dd.mm.yy ' is different from dd.MM.yy

' MM ' for the month

' mm ' for a minute

see the link http://plugins.jquery.com/project/jquery-dateFormat for more details.

+2
source

Does it help:

  $ (function () {
        var m = new Date ("01", "10", "2011");
             m = $ .datepicker.formatDate ('dd MM yy', m);
             $ ('# datepicker'). datepicker ("setDate", m);
     });     

The above code worked for me when setting the date. Hope this works for you too.

+1
source

Source: https://habr.com/ru/post/1381334/


All Articles