Kendo DateTimePicker 不处理 UTC 偏移量 [英] Kendo DateTimePicker Not Handling UTC Offset

查看:35
本文介绍了Kendo DateTimePicker 不处理 UTC 偏移量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们使用的是使用 AngularJS 指令实现的 Kendo 日期时间选择器:

We are using the Kendo datetimepicker, implemented using the AngularJS directives:

<input type="text" kendo-date-time-picker k-ng-model="TheDateModel">

其中:TheDateModel = 2016-02-15 20:58:24.0000000 +00:00

Where: TheDateModel = 2016-02-15 20:58:24.0000000 +00:00

我在 CST 时区,与 GMT 相差 -6 小时.datetimepicker 的当前结果显示时间为 8:58 pm,但我的预期结果是 2:58 pm.

I am in the CST timezone, which is -6 hour offset from the GMT. The current result of the datetimepicker shows a time of 8:58 pm but my expected result is 2:58 pm.

我到底做错了什么?

推荐答案

免责声明:我为 Kendo UI 团队工作

Disclaimer: I work for Kendo UI team

Kendo UI Datepicker 在内部使用 JavaScript Date 对象来保存选定的日期值.您可能知道,它始终使用本地(浏览器)时区.我们也试图在我们的文档中解释这个警告:

The Kendo UI Datepicker uses JavaScript Date object internally to hold the selected date value. As you probably know, it always uses the local (browser) timezone. We tried to explain that caveat in our docs too:

由于此默认行为,小部件将使用已转换的日期值(具有应用的本地时区).小部件不会操作值时区,因为它没有足够的信息来操作.

Due to this default behavior, the widget will use the already converted Date value (with the applied local timezone). The widget doesn't manipulate the value timezone, as it does not have sufficient information how to do that.

解决方案

在这种情况下,最好的方法是在提供 DatePicker 小部件之前手动转换日期字符串(如您提到的2016-02-15 20:58:24.0000000 +00:00").例如,这是一种可能的方法:

The best approach in this case is to convert the Date strings (like the one you mentioned "2016-02-15 20:58:24.0000000 +00:00") manually before feed the DatePicker widget. For instance, here is one possible approach to do that:

注意在 loadData 方法中如何解析和调整值.类似的事情应该由需要在他们的应用中处理不同 TZ 的开发者完成.

Notice how the value is parsed and then adjusted in the loadData method. Similar thing should be done by the developer that needs to handle different TZ in their app.

这篇关于Kendo DateTimePicker 不处理 UTC 偏移量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆