JQuery UI Datepicker date format issue with initial value

后端 未结 5 2198
梦毁少年i
梦毁少年i 2020-12-06 01:29

I need to set the initial date for the date picker to 03/20/2010 in mm-dd-yyyyy format. I have done this



        
相关标签:
5条回答
  • 2020-12-06 02:06

    You need a combination of dateFormat and defaultDate options:

    $("#datepicker").datepicker(
    {
        dateFormat: 'mm/dd/yyyy',
        defaultDate: '20/03/2010'
    });
    

    there are, however, many different ways to specify the default date. I'm not sure what you need so you can reference the API here: http://docs.jquery.com/UI/Datepicker#option-defaultDate.

    0 讨论(0)
  • 2020-12-06 02:08

    mm equals minutes not months.
    Use dd/MM/yyyy instead.

    0 讨论(0)
  • 2020-12-06 02:12

    Also remember that type="date" will make issue, so set type as text.

    0 讨论(0)
  • 2020-12-06 02:17

    Not accurate!!!

    $("#datepicker").datepicker(
    {
        dateFormat: 'mm/dd/yyyy',
        defaultDate: '20/03/2010'
    });
    

    You must to put the right format in dateFormat : for your example there is : dd/mm/yy two mistake:

    • day/month inversion
    • year is only two 'y' not four
    0 讨论(0)
  • 2020-12-06 02:18
    $('#datepicker').datepicker('option', 'dateFormat', 'dd-mm-yy');
    

    Year is specified as y for 2 digits and yy for 4 digits, as stated here.

    0 讨论(0)
提交回复
热议问题