jQuery datepicker不断重置Hour值

时间:2016-03-18 14:33:18

标签: javascript

我创建了2 datepickers并且它们都工作正常,问题是它们没有保留Hour值,它们会将值重置为00:00:00即使我在分配date之前设置不同的小时。我错过了什么或做错了什么?

 var fromDate = $("#startDate").datepicker({
            defaultDate: "+1w",
            changeMonth: true,
            numberOfMonths: 1,
            onSelect: function(selectedDate) {
                var instance = $(this).data("datepicker");
                var date = $.datepicker.parseDate(instance.settings.dateFormat || $.datepicker._defaults.dateFormat, selectedDate, instance.settings);
                date.setDate(date.getDate()+1);
                date.setHours(23,59,59);
                toDate.datepicker("option", "minDate", date);
            }
        });
        var dStart = new Date();
        dStart.setMonth(dStart.getMonth() - 1);
        fromDate.datepicker("setDate", dStart);

        var toDate = $("#endDate").datepicker({
            defaultDate: "+1w",
            changeMonth: true,
            numberOfMonths: 1
        });
        var dEnd = new Date();
        dEnd.setHours(23,59,59);
        console.log(dEnd);
        toDate.datepicker("setDate", dEnd);

        console.log(fromDate.datepicker("getDate"));
        console.log(toDate.datepicker("getDate"));

console.log结果如下:

statsHelper.js:36 Fri Mar 18 2016 23:59:59 GMT+0100 (ora solare Europa occidentale)
statsHelper.js:37 Thu Feb 18 2016 00:00:00 GMT+0100 (ora solare Europa occidentale)
statsHelper.js:38 Fri Mar 18 2016 00:00:00 GMT+0100 (ora solare Europa occidentale)

0 个答案:

没有答案