在使用ASP.Net 3.5 / SQL Server 2005的网站使用的时区 [英] Using TimeZones on website using ASP.Net 3.5 / SQL Server 2005

查看:145
本文介绍了在使用ASP.Net 3.5 / SQL Server 2005的网站使用的时区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想确定,我应该如何实施当地时间一个web应用程序。所有的用户登录,没有匿名用户。他们需要看到他们的本地时间所有的时间值。

I am trying to determine, how I should implement local time in a web-app. All users are logged in, there are no anonymous users. They will need to see all time-values in their local time.

这是它应该怎么做?

  1. 所有DateTime值保存为UTC时间在数据库
  2. 在每个用户储存在他的个人资料一个UTC偏移值
  3. 当显示日期时间价值,我从数据库中的值,并应用用户所抵消。

这是要走的路?还是我失去了一些东西?

Is this the way to go? Or am I missing something?

推荐答案

不要存放UTC为用户偏移 - 这还不够,要知道全时区信息。您应该存储他们的 Olson时区ID ,例如: 欧洲/伦敦。然后你就可以显示在当地时间任何UTC时间,同时考虑到历史变化,夏令等。

Don't store a UTC offset for the user - that's not enough to know the full time zone information. You should store their Olson time zone ID, e.g. "Europe/London". Then you can display any UTC time in the local time, taking into account historical changes, daylight savings etc.

编辑:它看起来像的TimeZoneInfo ID实际上不是正常奥尔森格式 - 但只要有东西明智可以显示给用户(为选择),和一个ID你可以从以后检索区,这可能没关系......你可能会遇到困难,如果你需要在后面虽然与其他系统进行互操作。

It looks like the TimeZoneInfo ID isn't actually in the normal Olson format - but so long as there's something sensible you can display to the user (as a choice), and an ID you can retrieve the zone from later on, that's probably okay... you may have difficulties if you need to interoperate with other systems later though.

您应该的要求的为他们的时区的用户(可能首先尝试通过JavaScript猜吧) - 他们会比你做的更多信息

You should ask the user for their time zone (possibly trying to guess it first through JavaScript) - they will have more information than you do.

您应该调查的TimeZoneInfo 类更多关于这个 - 我不能说我已经用它自己多,但它的方式去作为.NET 3.5。特别是, FindSystemTimeZoneById 和的 GetSystemTimeZones 将是重要的

You should investigate the TimeZoneInfo class for more on this - I can't say I've used it much myself, but it's the way to go as of .NET 3.5. In particular, FindSystemTimeZoneById and GetSystemTimeZones will be important.

时区,一般疼痛,但至少的TimeZoneInfo 给出比老多了很多支持时区类型。

Time zones are a pain in general, but at least TimeZoneInfo gives a lot more support than the old TimeZone type.

这篇关于在使用ASP.Net 3.5 / SQL Server 2005的网站使用的时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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