1

我正在使用 jquery.datepicker,我需要以更易读的格式显示所选日期。这是我正在使用的代码:

    $(function(){
                $('#dp').datepicker({
                    dateFormat: 'yymmdd',
                    numberOfMonths: 3,
                    minDate: 0,
                    maxDate: 60
                });
                $('#date').on('click', function() {
                    $('#dp').datepicker('show');            
                });
                $("#dp").change(function() {
//#NEW DATE FORMAT = EDIT FORMAT OF #DP
                    $("#showDate").html($("#NEW DATE FORMAT").val());
                    $(".eventDate").addClass('eventAdded dateProvided');
                });
});

所以我需要转换#DP 的值,但仅用于#showDate.html 元素中的显示目的。我希望这是有道理的

4

2 回答 2

2
$("#dp").on("changeDate", function (ev) {
     var mydate= ev.date;// formate it as you like, as the the ev.date has date object
     alert("Day:"mydate.getDay() +"Month:"mydate.getMonth()+"Year:"mydate.getFullYear())
});
于 2013-09-06T12:13:47.420 回答
0

您可以使用 datepicker 内部 formatDate 函数。

这是一个jsfiddle示例

$('#dp').datepicker({
    dateFormat: 'yymmdd',
    numberOfMonths: 3,
    minDate: 0,
    maxDate: 60
});

$("#dp").change(function () {
    var tempDate = $('#dp').datepicker('getDate');
    var newformattedDate = $.datepicker.formatDate('dd-mm-yy', tempDate);
    $("#showDate").html(newformattedDate);
});
于 2013-09-06T12:08:18.850 回答