Default date in an input

2

I have this snippet of code that shows a datepicker with the use of Jquery

$(function () {
        $('#orderDate').datepicker({
            dateFormat: 'dd-mm-yy'
        })
    })

    $("#orderDate").datepicker().datepicker("setDate", new Date());
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

It shows me the datepicker and I take the value, but I put it in "MM-DD-YY" format as I show in the image and I would like it to be in dd-mm-yy format

Thanks

    
asked by ilernet 24.05.2017 в 11:39
source

2 answers

1

If you are using jQuery UI, it should work.

If you are using any other plugin you should check its documentation.

Here is an example with jQuery UI working:

    $(function () {
        $('#orderDate').datepicker({
            dateFormat: 'dd-mm-yy'
        });
        $("#orderDate").datepicker().datepicker("setDate", new Date());
    });
<link href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<input id="orderDate" type="text">
    
answered by 24.05.2017 / 11:55
source
3

Try with / instead of -

$('#orderDate').datepicker({ dateFormat: 'dd/mm/yy' });
    
answered by 24.05.2017 в 11:44