Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set locale format from datepicker?

How can I set the date format in jQuery UI's datepicker according to the user's locale?

I get source html:

<script type="text/javascript">
    $(function() {
        $(".datefield2").datepicker($.datepicker.regional['de']);
    });
</script>
<form action="/Home/TestDate" method="post">    <input class="datefield2 hasDatepicker valid" name="date" value="21.12.2012" type="text" id="date">
    <input type="submit" value="send">
</form>

If a select a date in the datepicker I get 12/21/2012, however I need 21.12.2012.

like image 480
Mediator Avatar asked Dec 21 '12 16:12

Mediator


2 Answers

Use the dateFormat option to change to a custom format

$(function() {
    $(".datefield2").datepicker($.datepicker.regional['de']);
    $(".datefield2").datepicker('option','dateFormat','dd.mm.yy');
});

The real issue is that you need to manually include the localization files.

They can be found at https://github.com/jquery/jquery-ui/tree/master/ui/i18n
The one specific for german is https://github.com/jquery/jquery-ui/blob/master/ui/i18n/datepicker-de.js

Demo (with full localization) can be seen at http://jsfiddle.net/gaby/h07ny9ep/

like image 181
Gabriele Petrioli Avatar answered Sep 20 '22 10:09

Gabriele Petrioli


You can set the date format like this:

  $(".datefield2").datepicker({ "dateFormat": "dd.mm.yy"});
like image 34
Fiona - myaccessible.website Avatar answered Sep 22 '22 10:09

Fiona - myaccessible.website