Kendo UI 调度程序时区问题

Kendo UI Scheduler TimeZone issue

创建新事件时,会从数据库中适当地存储和提取数据。但是,kendo ui 调度程序没有正确显示。例如,我为“2016-10-31 09:00:00.000”创建了一个事件,它显示在“2016-10-30 10:00 PM”的 UI 上。我验证了服务返回的值,它是 1477864800000,在控制台上它被打印为 "Mon Oct 31 2016 09:00:00 GMT+1100 (AUS Eastern Daylight Time)".

请指教,我需要提到的地方 时区:"Etc/UTC",或者我的 JS 代码可能出了什么问题。

            $(function () {
                    $("#scheduler").kendoScheduler({
                        date: new Date(),            
                        height: 600,
                        views: [
                          "day",
                          { type: "week", selected: true },
                          "month"
                        ],
                        editable: {
                            template: $("#customEditorTemplate").html(),
                        },
                        timezone: "Etc/UTC",
                        error: error_handler,            
                        dataSource: {
                            timezone: "Etc/UTC",
                            batch: true,                
                            transport: {
                                read: {
                                    url: "GetCalendarEvents",
                                    contentType: "application/json; charset=utf-8",
                                    dateType: "json"
                                },
                                update: {
                                    url: "UpdateCalendarEvent",
                                    contentType: "application/json; charset=utf-8",
                                    dataType: "json"
                                },
                                create: {
                                    url: "InsertCalendarEvent",
                                    contentType: "application/json; charset=utf-8",
                                    dataType: "json"
                                },
                                destroy: {
                                    url: "DeleteCalendarEvent",
                                    contentType: "application/json; charset=utf-8",
                                    dataType: "json"
                                },
                                parameterMap: function (options, operation) {
                                    if (operation === "read") {
                                        var scheduler = $("#scheduler").data("kendoScheduler");

                                        var result = {
                                            CreatedDate: new Date(new Date().getFullYear(), new Date().getMonth() - 6, new Date().getDate(), 0, 0, 0, 0), 
                                            EndDate: new Date(new Date().getFullYear(), new Date().getMonth() + 6, new Date().getDate(), 0, 0, 0, 0),
                                            Creator: 1378 // ToDo::                                
                                        }

                                        return { models: kendo.stringify(result) };
                                    }

                                    if (operation !== "read" && options.models) {
                                        return { models: kendo.stringify(options.models) };
                                    }
                                }
                            },
                            schema: {
                                model: {
                                    "id": "EventID",
                                    "fields": {
                                        "EventID": {
                                            "type": "number"
                                        },
                                        "InteractionID":{
                                            "type":"number"
                                        },
                                        "title": {
                                            "from": "Subject",
                                            "validation": { required: true }
                                        },
                                        "description": {
                                            "from": "Content"
                                        },
                                        "start": {
                                            "from": "CreatedDate",
                                            "type": "date"
                                        },
                                        "end": {
                                            "from": "EndDate",
                                            "type": "date"
                                        },
                                        "ownerId": {
                                            "from": "Creator",
                                            "type": "number"
                                        },
                                        "location": {
                                            "from": "Location",
                                            "type": "string"
                                        },
                                        "Attendees": {
                                            "type": "object"
                                        },
                                        "startTimezone": {
                                            "defaultValue": "Etc/UTC"
                                        },
                                        "endTimezone": {
                                            "defaultValue": "Etc/UTC"
                                        }
                                    }
                                }
                            }
                        }
                    });
                });

解决方案是在实体 class 中以 UTC 格式设置 CreatedDate 和 EndDate。

    private System.DateTime _endDate;
    public DateTime EndDate
    {
        get
        {
            return _endDate;
        }
        set
        {
            _endDate = new DateTime(value.Value.Ticks, DateTimeKind.Utc);
        }
    }

此外,不需要在 DataSource 和 Schema 中设置时区。仅在调度程序级别应该没问题。

希望对您有所帮助。