DateTime选择器错误

时间:2014-10-30 07:48:31

标签: jquery datetime picker

我正在使用jquery日期时间选择器,当我打开那些选择器所在的页面时,两个选择器值都是当前时间(例如:2014年11月1日星期六08:27:28 GMT + 0200(FLE标准时间)) 。如何设置12:00默认选择值,而不是当前时间?

谢谢你们......

http://jsfiddle.net/4fa5n7wa/6/

$(document).ready(function () {
    var today = new Date();

    var minStart = new Date();
    minStart.setDate(today.getDate() + 2);

    var minEnd = new Date(minStart);
    minEnd.setDate(minEnd.getDate() + 2);

    $("#start").datetimepicker({
        format: "Y/m/d H:i",
        dayOfWeekStart: "1",
        value: "12:00",
        inline: true,
        lang: "nl",
        onSelectDate: function (ct) {
            var diff = CalcDiff();

            var minDate = new Date(ct);
            minDate.setDate(minDate.getDate() + 2);

            if (diff > 48)
                var defDate = new Date($("#end").val());

            $("#end").datetimepicker("destroy");
            $("#end").datetimepicker({
                format: "Y/m/d H:i",
                dayOfWeekStart: "1",
                value: "12:00",
                inline: true,
                lang: "nl",
                minDate: minDate,
                defaultDate: defDate || minDate,
                onSelectDate: function (ct) {
                    CalcDiff();
                },
                onSelectTime: function (ct) {
                    CalcDiff();
                }
            }).val(defDate || minDate);

            CalcDiff();
        },
        onSelectTime: function (ct) {
            CalcDiff();
        },
        minDate: minStart,
        defaultDate: minStart
    }).val(minStart);

    $("#end").datetimepicker({
        format: "Y/m/d H:i",
        dayOfWeekStart: "1",
        value: "12:00",
        inline: true,
        lang: "nl",
        minDate: minEnd,
        defaultDate: minEnd,
        onSelectDate: function (ct) {
            CalcDiff();
        },
        onSelectTime: function (ct) {
            CalcDiff();
        }
    }).val(minEnd);

    CalcDiff();
});

function CalcDiff() {
    var start = new Date($("#start").val());
    var end = new Date($("#end").val());

    if (start != null && end != null) { // We have both dates
        var hours = Math.abs(end - start) / 36e5;
        $("#difference").val(hours);
    }

    return hours;
}

1 个答案:

答案 0 :(得分:1)

问题解决了:

  minStart.setHours(12); 
  minStart.setMinutes(00); 

  minEnd.setHours(12); 
  minEnd.setMinutes(00);