我在 Kendo 日期和时间选择器中得到了错误的时间

问题描述 投票:0回答:1

当我设置时间时,我得到了错误的日期,例如。如果我选择时间为 19:51:30 pm,那么我将得到 07:51:30 am。但我想要同样的时间,我选择但没有得到。

我尝试了与剑道时间选择器相关的所有操作,但没有得到我选择的正确时间。

这是我的代码:

var startDatePicker = $("#datetimepicker1").kendoDateTimePicker({
            value: new Date(),
            format: "MM/dd/yyyy hh:mm:ss tt",
            dateInput: true,
            timeFormat: "hh:mm:ss tt",
            componentType: "modern",
            max: new Date(),
            timezone: "Etc/GMT+5"
        }).data("kendoDateTimePicker");

        var endDatePicker = $("#datetimepicker2").kendoDateTimePicker({
            value: new Date(),
            format: "MM/dd/yyyy hh:mm:ss tt",
            dateInput: true,
            timeFormat: "hh:mm:ss tt",
            componentType: "modern",
            max: new Date(),
            timezone: "Etc/GMT+5",
            min: startDatePicker.value(),
            month: {
                // Customize the cell template for the datepicker
                content: function (e) {
                    var currentDate = e.date.getDate();
                    var startDate = startDatePicker.value().getDate();
                    var endDate = endDatePicker.value().getDate();
                    var isDisabled = currentDate < startDate || currentDate > endDate;
                    
                    if (isDisabled) {
                        e.html = "<span class='k-disabled'>" + currentDate + "</span>";
                    }
                }
            }
        }).data("kendoDateTimePicker");

        startDatePicker.bind("change", function() {
            endDatePicker.min(startDatePicker.value());
        });
javascript kendo-ui kendo-datetimepicker kendo-timepicker
1个回答
0
投票

您已将时区设置为“Etc/GMT+5”,这意味着您选择的时间将调整为GMT+5。 如果您希望 DateTimePicker 使用用户浏览器的本地时区,您可以从配置中删除时区选项:

 var startDatePicker = $("#datetimepicker1").kendoDateTimePicker({
    value: new Date(),
    format: "MM/dd/yyyy hh:mm:ss tt",
    dateInput: true,
    timeFormat: "hh:mm:ss tt",
    componentType: "modern",
    max: new Date()
}).data("kendoDateTimePicker");

var endDatePicker = $("#datetimepicker2").kendoDateTimePicker({
    value: new Date(),
    format: "MM/dd/yyyy hh:mm:ss tt",
    dateInput: true,
    timeFormat: "hh:mm:ss tt",
    componentType: "modern",
    max: new Date(),
    min: startDatePicker.value(),
    month: {
        // Customize the cell template for the datepicker
        content: function (e) {
            var currentDate = e.date.getDate();
            var startDate = startDatePicker.value().getDate();
            var endDate = endDatePicker.value().getDate();
            var isDisabled = currentDate < startDate || currentDate > endDate;

            if (isDisabled) {
                e.html = "<span class='k-disabled'>" + currentDate + "</span>";
            }
        }
    }
}).data("kendoDateTimePicker");

startDatePicker.bind("change", function () {
    endDatePicker.min(startDatePicker.value());
});
© www.soinside.com 2019 - 2024. All rights reserved.