时区敏感的日期和时间显示在Web应用程序? [英] Time Zone Sensitive Date and Time Display in Web Applications?

查看:186
本文介绍了时区敏感的日期和时间显示在Web应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要寻找的在一个时区不是用户当前时区以外的Web应用程序中显示时间的建议。

我们保存我们的日期/时间在UTC / GMT在数据库中,所以它不是一个问题,格式化时间UTC / GMT或用户的当前时区。但是,在其他情况下,我们需要显示但从任意时间段的点的时间(即此页面上的每个日期/时间是在东方,无论用户是否是西海岸,中欧,东欧的,等等。)。

We store our dates/times in UTC/GMT in the database, so it is not an issue to format the time for UTC/GMT or the user's current time zone. However, in other situations we need to display the time from the point of view of an arbitrary time zone (i.e. every date/time on this page is in Eastern, regardless of whether or not the user is in West Coast, Central, Eastern, etc.).

在过去,我们已经存储的偏移量或时区信息,然后进行计算服务器code。在.NET或其他人,我们也做了一些客户端的操作在JavaScript中,我将preFER避免,因为这一切都变得非常依赖于JavaScript和用户的浏览器。我想知道,为此在一个更客户端/ MVC类型的应用程序的最佳方式。

In the past we have stored offsets or time zone info, then done the calculations in server code in .Net or else we have done some client-side manipulations in javascript that I would prefer to avoid, since it all becomes very dependent on javascript and the user's browser. I'd like to know the best way to do this in a more client-side/MVC type application.

下面是一个例子:

  1. 存储在数据库日期:1302790667(星期四,2011 4月14日14时17分四十七秒GMT)
  2. 在转换后的日期显示在中央时区的客户:星期四04月14日9点17分47秒2011
  3. 日期其实我是想显示,总是在东部时区:星期四04月14日10时17分47秒2011

在上面的例子中,很容易获得的UTC时间(#1)或用户的当前时区(#2),但它更难以得到#3。我的选择似乎是:

In the above example, it's easy to get the time in UTC (#1) or the user's current time zone (#2) but it is more difficult to get #3. My options seem to be:

    在db
  1. 存储偏移或时区,并做计算在客户端上 - 这就是我们过去与.net做了,但它似乎连梅西耶在客户端code是我们目前正在努力的路径避免的。
  2. 请在服务器上的转换并发送下一个完整的日期显示到客户端 - 客户端接收一个字符串(星期四04月14日10时17分47秒2011)。这工作,但它不是很灵活。
  3. 请在服务器上的转换,把它拆成零件,并把这些到客户端,然后把他们重新走到一起。 ({工作日:周四,月:月,日:14,小时:10分:17})。这给我们正确的数据,为我们提供了更多的灵活性,格式化日期,但感觉有点不对劲了此方案。

任何其他的想法选择吗?如何处理其他类似的情况?谢谢你。

Any other options ideas? How do others handle similar situations? Thanks.

推荐答案

我们的结果:

  1. 在我尝试了一些库像Datejs,MS阿贾克斯,等等,我一直都不是很满意。 Datejs没有在我的几个测试案例在所有的工作,不积极维护,并且似乎集中了很多语法糖,我们不需要(date.today()。第一个()。周四()等)
  2. 我们不使用jQuery一些基本的日期/时间分析。
  3. 在我碰到了很多滚你自己的客户端的日期转换黑客,其中大部分只涉及转化为UTC,开始了做工精细,并最终在一些边缘的情况下崩溃了。 这一次对于很多90%溶液标准UTC转换,但并没有解决我们的乱时区的问题。
  1. I tried out a few libraries like Datejs, MS Ajax, etc. and I was never very happy with them. Datejs didn't work at all in a few of my test cases, is not actively maintained, and seemed to focus a lot on syntactic sugar that we don't need (date.today().first().thursday(), etc.)
  2. We do use jQuery for some basic date/time parsing.
  3. I came across a lot of "roll-your-own" client-side date conversion "hacks", most of which only addressed the conversion to UTC, started off working fine, and then eventually fell apart on some edge case. This one was the 90% solution for a lot of standard UTC conversion but didn't solve our "arbitrary timezone" issue.

之间的code的复杂性增加了转换例程,他们似乎导致的错误,我们决定,以避免客户端数据处理的大部分时间。我们做的日期转换服务器与我们现有的日处理例程,并通过格式化日期或信息跌要使用的视图属性。如果我们需要一个单独的日子里,我们只需要添加另一个属性。有迹象表明,我们需要在同一时间(即EventDateUTC,EventDateLocal,EventDateAlwaysAustralia和EventDayOfWeek)通常只有几个属性。

这篇关于时区敏感的日期和时间显示在Web应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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