get selected value in datePicker and format it

前端 未结 4 1842
花落未央
花落未央 2021-02-10 02:01

In the datePicker selected 20.04.2012. I want to get this value, format it and store in a variable. I uses this code:

var date = $(\"#scheduleDate\"         


        
相关标签:
4条回答
  • 2021-02-10 02:15

    If you want to take the formatted value of input do this :

    $("input").datepicker({ dateFormat: 'dd, mm, yy' });
    

    later in your code when the date is set you could get it by

    dateVariable = $("input").val();
    

    If you want just to take a formatted value with datepicker you might want to use the utility

    dateString = $.datepicker.formatDate('dd, MM, yy', new Date("20 April 2012"));
    

    I've updated the jsfiddle for experimenting with this

    0 讨论(0)
  • 2021-02-10 02:17
    $('#scheduleDate').datepicker({ dateFormat : 'dd, MM, yy'});
    
    var dateFormat = $('#scheduleDate').datepicker('option', 'dd, MM, yy');
    
    $('#scheduleDate').datepicker('option', 'dateFormat', 'dd, MM, yy');
    
    var result = $('#scheduleDate').val();
    
    alert('result: ' + result);
    

    result: 20, April, 2012

    0 讨论(0)
  • 2021-02-10 02:32

    Use jquery-dateFormat. It will solve your problem.

    You need to include the jquery.dateFormat in your html file.

    <script>
    var date = $('#scheduleDate').val();
    document.write($.format.date(date, "dd,MM,yyyy"));
    
    var dateTypeVar = $('#scheduleDate').datepicker('getDate');
    document.write($.format.date(dateTypeVar, "dd-MM-yy"));
    </script>
    
    0 讨论(0)
  • 2021-02-10 02:34
    var dateObject = $("#datePickerInput").datepicker('getDate');
    $.datepicker.formatDate('dd MM, yy', dateObject);
    
    0 讨论(0)
提交回复
热议问题