Kendo UI UTC日期发布

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

我有一个奇怪的问题,即我们的网格的编辑模板在编辑日期时引起问题。

日期以UTC时区存储在服务器上。我使用以下模式设置时区:-

private DateTime _minDate;
public DateTime MinDate
{
    get { return _minDate; }
    set { _minDate = DateTime.SpecifyKind(value, DateTimeKind.Utc); }
}

使用WebApi OData服务将日期加载到网格中。

{
    "Id":50088,
    "ProductId":101437,
    "Valor":"12224000",
    "ISIN":"CH0122240002",
    "Description":"Outperformance Bonus Certificate, Multi Shares",
    "Provider":"CSIB",
    "AlertedTicker":"KO UN",
    "ProtectionPercentage":1.0,
    "ProtectionType":"Protection Lost",
    "UnderlyingCurrency":"USD",
    "BarrierLevel":190.0,
    "BarrierPercentage":70.0,
    "BarrierType":"Low",
    "BarrierId":0,
    "EventStructureId":170378,
    "Date":"2013-11-20T00:00:00Z",
    "Comment":null,
    "Confirm":false,
    "Reject":false
}

OData服务正确地序列化了UTC日期,并且日期完整地到达了UI。

使用日期选择器控件编辑日期,但仅使用键盘键入数据后,数据就以错误的格式发送回服务器。

{
    "odata.metadata":"http://local.host:51850/web/odata/$metadata#PendingBarrierAlerts/@Element",
    "Id":50088,
    "ProductId":101437,
    "Valor":"12224000",
    "ISIN":"CH0122240002",
    "Description":"Outperformance Bonus Certificate, Multi Shares",
    "Provider":"CSIB",
    "AlertedTicker":"KO UN",
    "ProtectionPercentage":1.0,
    "ProtectionType":"Protection Lost",
    "UnderlyingCurrency":"USD",
    "BarrierLevel":190.0,
    "BarrierPercentage":70.0,
    "BarrierType":"Low",
    "BarrierId":0,
    "EventStructureId":170378,
    "Date":"2013-11-20T23:00:00Z",
    "Comment":null,
    "Confirm":false,
    "Reject":false
}

注意日期已更改时间!

我如何在网格中编辑UTC日期,并使用OData作为传输和远程数据源将它们正确地返回到服务器?

date datepicker kendo-ui utc
2个回答
1
投票

日期总是在客户端创建为本地日期(而不是UTC日期)。为了拦截并避免结果发生,您需要在Grid / DataSource开始使用它们之前使用requestEnd事件转换这些日期。

您可以看到here涵盖了类似的方法。


1
投票

为了避免@PeturSubev所说的,我正在parse中实现正确初始化日期的DataSource.model函数。

dataSource:{
    ...
    schema:{
        parse:function (response) {
            $.each(response, function (idx, elem) {
                if (elem.Date && typeof elem.Date === "string") {
                    elem.Date = kendo.parseDate(elem.Date, "yyyy-MM-ddTHH:mm:ss.fffZ");
                }
            });
            return response;
        }
    }

}

因此,我让KendoUI随心所欲地使用它们。

© www.soinside.com 2019 - 2024. All rights reserved.