ASP.NET/SQL 时区之谜
设置:Windows Server 2003 / SQL Server 2005。ASP.NET 2.0。 IIS 6。
我正在处理的网站使用 ASP.NET 会员资格,创建用户时会将其插入到 aspnet_membership 数据库中。
所有服务器均设置为中部时间。 我还通过在 SQL Server 上执行 Select GetDate()
验证了这一点,它返回了中心时间。
但是,当用户插入到 aspnet_membership 中时,他们的 CreateDate 会以 GMT 格式列出。 (格林威治标准)。
我查看了代码,发现与创建成员相关的任何地方都没有 NO DateTime.Now.AddHours(6);
。
会员资格默认只使用 GMT 吗? 这可以在某个地方改变吗? 使用 GMT 有什么优势吗? 我没有在用户方面做任何时区细节,所以我认为没有必要。
无论如何,如果您对我所忽略的内容有任何想法,我将不胜感激。
谢谢你!
Setup: Windows Server 2003 / SQL Server 2005. ASP.NET 2.0. IIS 6.
The site I'm working on uses ASP.NET Membership and when a user is created it is inserted into the aspnet_membership database.
All servers are set at Central Time. I also verified this by doing a Select GetDate()
on SQL Server and it returned central time.
However, when a user is inserted into aspnet_membership, their CreateDate is listed in GMT. (Greenwich Mean).
I've looked at the code and there is NO DateTime.Now.AddHours(6);
anywhere associated with creating members.
Does Membership just uses GMT by default? Can this be changed somewhere? Is there any advantage to using GMT? I'm not doing any Timezone specifics on the users side, so I see no need for it.
Anyway if you have any ideas on what I'm overlooking it would be greatly appreciated.
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 UTC(而不是 GMT)还有一个额外的好处,那就是您不必担心夏令时。
如果您查看 dbo.aspnet_Membership_CreateUser 存储过程,您会发现一个 @CurrentTimeUtc 参数,该参数向我表明 ASP.NET 成员资格中的所有日期时间确实是 UTC。
您可以使用 DateTime.ToLocalTime 转换为本地(服务器)时间。
Using UTC (not GMT) has the additional advantage that you don't have to worry about Daylight saving.
If you look at the dbo.aspnet_Membership_CreateUser stored procedure you find a @CurrentTimeUtc parameter, which suggets to me that all datetimes in the ASP.NET Membership are indeed UTC.
You can use the DateTime.ToLocalTime to convert to local (server) time.
成员资格会自动使用 UTC,如本文所述:
https://web. archive.org/web/20210309215647/http://aspnet.4guysfromrolla.com/articles/041608-1.aspx
Membership does automatically use UTC as described in this article:
https://web.archive.org/web/20210309215647/http://aspnet.4guysfromrolla.com/articles/041608-1.aspx