Jquery datepicker format date not working

后端 未结 12 2109
我在风中等你
我在风中等你 2021-01-01 22:23

Here is my code:

$(function () {
    $(\"#datepicker\").datepicker({ dateFormat: \'DD-MM-YY\' });
});

And the datetime picker is shown, but

相关标签:
12条回答
  • 2021-01-01 23:08

    Try this:

    $(function() {
        $('#datepicker').datepicker({
            dateFormat: 'dd/mm/yy',
        }).datepicker('option', 'dateFormat', 'dd/mm/yy');
    });
    

    It works 100%.

    0 讨论(0)
  • 2021-01-01 23:11

    Setting the default format will solve the problem, this solution works for me while all above do not.

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

    Source: Datepicker: Adding dateFormat is giving an error

    0 讨论(0)
  • 2021-01-01 23:11

    Full example:

    In jsp:

    <div id="datepicker"></div>
    

    In script:

    function datepicker() {
    
      $("#datepicker").datepicker({
        showButtonPanel: true,
        dateFormat: 'yy-mm-dd',
        onSelect: function() {
            var dateObject = $('#datepicker').datepicker().val();
            alert(dateObject);
        }
       }
      );
    }
    
    0 讨论(0)
  • 2021-01-01 23:11

    this one works for me

    $('#datepicker').datepicker({ format: 'dd-mm-yyyy' });
    
    0 讨论(0)
  • 2021-01-01 23:16

    C#:-

     [Column(TypeName = "date")]
            [Display(Name = "Date of Birth")]
            [Required]
            [DataType(DataType.Date)]
            [DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
            public DateTime? DOB { get; set; }
    

    CSHTL:-

     @Html.EditorFor(model => model.DOB, new { htmlAttributes = new { @class = "form-control" , @required = "required", @autocomplete="off"} })
    
            $(document).ready(function () {
            var validationerror = false;
             $('input[type=date]').datepicker({
                 dateFormat: "yy-mm-dd",
                 changeMonth: true,
                 changeYear: true,
                 yearRange: "-60:+0"
             });
    
    0 讨论(0)
  • 2021-01-01 23:18
    $('.datepicker').datepicker({
            format: 'dd-mm-yyyy',
            autoclose: true
        })
    
    0 讨论(0)
提交回复
热议问题