【问题标题】:UTC converted to Central Europe Standard Time is 2 hours in front not 1转换为中欧标准时间的 UTC 是前面 2 小时而不是 1
【发布时间】:2016-08-15 13:05:15
【问题描述】:

我试图了解为什么我的日期是错误的:

DateTime databaseUtcTime = new DateTime(2016, 8, 15, 10, 20, 0, DateTimeKind.Utc);
var timeZone = TimeZoneInfo.FindSystemTimeZoneById("Central Europe Standard Time");
var testDateTime = TimeZoneInfo.ConvertTimeFromUtc(databaseUtcTime, timeZone);

testDateTime 输出 15/08/2016 12:20:00 而不是 15/08/2016 11:20:00 这是为什么呢?不应该比 UTC 提前 1 小时,而不是 2 小时吗?

编辑----

感谢乔恩·斯基特,

如果这对任何人有帮助,我会使用:

if(testDateTime.IsDaylightSavingTime())
{
    testDateTime = testDateTime.AddHours(-1);
}

尽管您不知道上下文,但这可能有助于了解如何在按时运行某些显式测试时摆脱夏令时。

【问题讨论】:

标签: c# datetime timezone


【解决方案1】:

ID 为“中欧标准时间”的时区只是中欧使用的时区...它真的不是标准时间。

由于中欧目前正在观察夏令时,因此偏移量实际上是 UTC+2。

很遗憾,Windows 时区中使用的 ID 具有这样的误导性……但 TimeZoneInfo 实现本身是正确的。

(这并不是 Windows 时区名称的全部问题...有关更多信息,请参阅 Matt Johnson's 帖子...)

【讨论】:

  • Jon Skeet,Jo(h)n Cena 的程序员版本。
  • @Jimmyt1988 人们会争论这是否是一种恭维,因为您将他与反应不一的人进行了比较。斯基特先生并非如此。
  • 哈哈哈@user3185569 - 对不起,我应该说查克诺里斯。
猜你喜欢
  • 2014-05-09
  • 2012-02-14
  • 2020-11-26
  • 2015-09-28
  • 2016-08-06
  • 2020-05-19
  • 2019-01-12
  • 1970-01-01
相关资源
最近更新 更多