Difference between UTC and GMT Standard Time in .NET(.NET 中 UTC 和 GMT 标准时间之间的差异)
问题描述
在 .NET 中,以下语句返回不同的值:
In .NET, the following statements return different values:
Response.Write(
TimeZoneInfo.ConvertTime(
DateTime.Parse("2010-07-01 5:30:00.000"),
TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time"),
TimeZoneInfo.FindSystemTimeZoneById("GMT Standard Time"))
);
// displays 7/1/2010 1:30:00 PM
..还有这个...
Response.Write(
TimeZoneInfo.ConvertTime(
DateTime.Parse("2010-07-01 5:30:00.000"),
TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time"),
TimeZoneInfo.FindSystemTimeZoneById("UTC"))
);
// displays 7/1/2010 12:30:00 PM
这是为什么?我认为 UTC 和 GMT 标准时间是等价的.
Why is this? I thought UTC and GMT Standard Time are equivalent.
更新
经过进一步测试,我发现以下似乎是等效的:
Upon further testing, I find that the following appear to be equivalent:
UTC"
格林威治标准时间"
摩洛哥标准时间"
然而,夏季月份的情况有所不同:
Whereas, the following is different during summer months:
格林威治标准时间"
也许我的问题应该是,为什么是格林威治标准时间"?和GMT 标准时间"不一样?
Perhaps my question should be, why are "Greenwich Mean Time" and "GMT Standard Time" different?
结束更新
推荐答案
GMT 不 调整 夏令时 (DST).您可以在这个 网站上听到马嘴里的声音.
GMT does not adjust for Daylight saving time (DST). You can hear it from the horse's mouth on this web site.
添加这行代码查看问题根源:
Add this line of code to see the source of the problem:
Console.WriteLine(TimeZoneInfo.FindSystemTimeZoneById("GMT Standard Time").SupportsDaylightSavingTime);
输出:真.
这不是 .NET 问题,而是 Windows 搞砸了.TimeZoneInfo 使用的注册表项是 HKLMSOFTWAREMicrosoftWindows NTCurrentVersionTime ZonesGMT 标准时间.你最好坚持使用 UTC.
This is not a .NET problem, it is Windows messing up. The registry key that TimeZoneInfo uses is HKLMSOFTWAREMicrosoftWindows NTCurrentVersionTime ZonesGMT Standard Time. You'd better stick with UTC.
这篇关于.NET 中 UTC 和 GMT 标准时间之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:.NET 中 UTC 和 GMT 标准时间之间的差异


- C# 中多线程网络服务器的模式 2022-01-01
- 输入按键事件处理程序 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01