我们如何在Sencha ExtJS版本6.0.2中设置我们要使用的时区? [英] How could we set globally in Sencha ExtJS version 6.0.2 the timezone that we want to use?

查看:133
本文介绍了我们如何在Sencha ExtJS版本6.0.2中设置我们要使用的时区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的目标是设置前端部分的时区,显示我们所期望的时区的日期/时间,并将日期字段,时间段等生成的日期设置为相同的时区,但最后发送正确的时间戳到服务器。

Our goal is to set the timezone on the frontend part to display the dates/times on the timezone that we desire and also get the dates generated from datefields, timefields etc. to be on the same timezone but at the end send the correct timestamp to the server.

根据这一点,将全局时区设置为一个javascript应用程序不是一个微不足道的任务:如何将javascript日期初始化为特定时区

Setting the timezone globally to a javascript application is not a trivial task according to this: How to initialize javascript date to a particular timezone

解决方案推荐像jQuery一样的库,如果我错了,请更正我,但这不符合sencha extjs的范围。换句话说,由sencha extjs处理的模型和组件中的时间转换太多,我们无法绕过。

The solutions recommend libraries like momentjs, and please correct me if I am wrong, but this is out of the scope and incompatible with sencha extjs. In other words there are too many time conversions in Models and Components handled by sencha extjs that we cannot bypass.

另外还有一个努力来覆盖Date的核心功能JavaScript语言本身的对象在这里找到: https://github.com/pligor/jstimezoner

虽然上面的工作原理简单的情况下,与sencha extjs应用程序集成结果是一个灾难,不推荐。

In addition there is an effort to override the core functionality of Date object of javascript language itself found here: https://github.com/pligor/jstimezoner
While the above works for simple cases when integrated with a sencha extjs application the outcome is a disaster and not recommended.

有没有我们缺少的配置这使得Sencha ExtJS可以在我们选择的时区显示和处理时间和日期?

Is there any configuration that we are missing that enables Sencha ExtJS to display and handle times and dates on a timezone of our choice?

请注意,我们始终向/从服务器发送/接收时间戳,因此在那里是没有时区的问题。

Note that we always send/receive a timestamp to/from the server and therefore there is no issue of timezones there.

推荐答案

就像ExtJS不支持国际化一样,它不支持时区。

Just like ExtJS doesn't really support internationalization, it doesn't support time zones.

我们搜索了ternet,也偶然发现MomentJS。但是当你发现,你可以开始重写几乎处理日期的ExtJS中的所有内容:你需要一个 datetimewzonepicker ,一个模型字段类型: 'datetimewzone' datetimewzonecolumn 等等。

We searched the internet and also stumbled upon MomentJS. But as you found out, you can then start to rewrite nearly everything in ExtJS that handles dates: You need a datetimewzonepicker, a model field of type:'datetimewzone', a datetimewzonecolumn and so on and so forth.

似乎太多的努力,我们决定在每个请求中将所需的客户端时区发送到服务器会更加容易,来回发送相应的 datetime Ymd H:i 格式,并在服务器上做关于时区的其他一切。现在我们后悔这个决定,因为这样我们无法在客户端计算(如离线模式下的cordova应用程序)。

Back then, it seemed too much of an effort and we decided that it would be easier to send the desired client time zone to the server in every request, sending the corresponding datetime back and forth in Y-m-d H:i format, and doing everything else regarding time zones on the server. We regret this decision now, because that way, we have no possibility to calculate on the client side (e.g. cordova app in offline mode).

如果您熟练使用ExtJS写所有这些momentdate处理的ExtJS扩展应该不仅是干净可扩展的,而且也是更简单的方法。

If you are proficient in ExtJS, writing all these momentdate-handling ExtJS extensions should be not only the clean and extensible, but also the easier way.

这篇关于我们如何在Sencha ExtJS版本6.0.2中设置我们要使用的时区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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