ASP.NET/SQL 时区之谜

发布于 2024-07-29 20:06:12 字数 552 浏览 10 评论 0原文

设置: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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

风吹雨成花 2024-08-05 20:06:13

使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文