GWT中的客户端时区支持 [英] Client side time zone support in GWT

查看:99
本文介绍了GWT中的客户端时区支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个GWT应用程序,我需要支持以下场景:

服务器位于时区A -
客户端的浏览器设置为时区B

GWT应用程序被配置为在时区C中显示日期/时间

由于GWT不支持Calendar和原生支持时间
区域在javascript中是不存在的我无法想象这个问题的一个很好和干净的
解决方案。



你们有没有做过什么您是否知道我可以使用的
utils?



谢谢!

解决方案根据我的经验,当处理gwt中的日期和时区时,以下最佳实践可显着降低复杂性和混淆:


  1. 每当在应用程序中操作/存储日期时,请将所有日期视为GMT时区以来的时间为自纪元以来的毫秒。您可以将它们存储为字符串或整型,它没有真正的区别。

  2. 每当向最终用户显示日期时,请使用适当的时区格式化日期。 b


    对于您的情况,当您在服务器上创建日期(时区A)时,将其转换为GMT以来的毫秒数,然后将其发送到客户端。在客户端上,使用 DateTimeFormat (或者编写自己的日期格式程序util),将其转换为时区B或时区C。


    I'm working on a GWT app where I need to support the following scenario:
    The server is located in time zone A
    The client's browser is set to time zone B
    The GWT app is configured to display date/time in time zone C

    Since GWT does not support Calendar and the native support for time zones in javascript is non-existent I can't think of a nice and clean solution to this problem.

    Have any of you done something similar or do you know of any good utils I could use?

    Thanks!

    解决方案

    In my experience, the following best practice significantly reduces complexity and confusion when dealing with dates and timezones in gwt:

    1. Whenever operating/storing dates within the application, treat all dates as milliseconds since epoch in GMT timezone. You can store them as string or int, it doesn't really make a difference.
    2. Whenever displaying the date to the end user, format the date using appropriate timezone.

    For your case, when you create a date on the Server (timezone A) convert it to milliseconds since epoch in GMT before sending it to the Client. On the client, use DateTimeFormat (or write your own date formatter util) to convert it into either timezone B or timezone C as appropriate.

    这篇关于GWT中的客户端时区支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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