.NET 中 UTC 和 GMT 标准时间之间的差异

1

本文介绍了.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 标准时间之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

C# 中的多播委托奇怪行为?
Multicast delegate weird behavior in C#?(C# 中的多播委托奇怪行为?)...
2023-11-11 C#/.NET开发问题
6

如何将代表存储在列表中
How to store delegates in a List(如何将代表存储在列表中)...
2023-11-11 C#/.NET开发问题
6

代表如何工作(在后台)?
How delegates work (in the background)?(代表如何工作(在后台)?)...
2023-11-11 C#/.NET开发问题
5

Delegate.CreateDelegate() 和泛型:错误绑定到目标方法
Delegate.CreateDelegate() and generics: Error binding to target method(Delegate.CreateDelegate() 和泛型:错误绑定到目标方法)...
2023-11-11 C#/.NET开发问题
14

函数委托与函数
Func Delegate vs Function(函数委托与函数)...
2023-11-11 C#/.NET开发问题
6

具有未知类型的 CreateDelegate
CreateDelegate with unknown types(具有未知类型的 CreateDelegate)...
2023-11-11 C#/.NET开发问题
5