jQuery UI DatePicker - Change Date Format

前端 未结 28 1777
后悔当初
后悔当初 2020-11-21 16:39

I am using the UI DatePicker from jQuery UI as the stand alone picker. I have this code:

And the

相关标签:
28条回答
  • 2020-11-21 17:09

    So I struggled with this and thought I was going mad, the thing is bootstrap datepicker was being implemented not jQuery so teh options were different;

    $('.dateInput').datepicker({  format: 'dd/mm/yyyy'})
    
    0 讨论(0)
  • 2020-11-21 17:09

    you should use data-date-format="yyyy-mm-dd" in your input field html and initial data picker in JQuery just like simple

    $("#issue_date").datepicker({ 
        dateFormat: "yy-mm-dd",
        changeMonth: true,
        changeYear: true
    });
    
    0 讨论(0)
  • 2020-11-21 17:10
    $("#datepicker").datepicker({ dateFormat: "yy-mm-dd" }).val()
    
    0 讨论(0)
  • 2020-11-21 17:11

    I think the correct way to do this would be something like this:

    var picker = $('.date-picker');
    var date = $.datepicker.formatDate(
        picker.datepicker('option', 'dateFormat'),
        picker.datepicker('getDate'));
    

    This way you make sure the format string is defined only once and you use the same formatter to translate the format string into the formatted date.

    0 讨论(0)
  • 2020-11-21 17:13

    I use this:

    var strDate = $("#dateTo").datepicker('getDate').format('yyyyMMdd');
    

    Which returns a date of format like "20120118" for Jan 18, 2012.

    0 讨论(0)
  • 2020-11-21 17:14

    This works smoothly. Try this.

    Paste these links in your head section.

    <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
    <script type="text/javascript"
            src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.4.1/js/bootstrap-datepicker.min.js"></script>
    <link rel="stylesheet"
          href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.4.1/css/bootstrap-datepicker3.css"/>
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
    <script src="http://code.jquery.com/ui/1.11.0/jquery-ui.js"></script>
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
    

    Following is the JS coding.

     <script>
    
            $(document).ready(function () {
                $('#completionDate').datepicker({
                    dateFormat: 'yy-mm-dd', // enter date format you prefer (e.g. 2018-10-09)
                    changeMonth: true,
                    changeYear: true,
                    yearRange: "-50:+10",
                    clickInput: true,
    
                    onSelect: function (date) {
                        loadMusterChit();
                    }
    
                });
            });
    
        </script>
    
    0 讨论(0)
提交回复
热议问题