我想用 .NET/C# 在另一个时区定义一天的开始。
示例:我当前的时区 = GMT+1 所以 DateTime.Today 返回 19/11/2009 23:00 UTC
但实际上我想获取时区 GMT+2 的 DateTime.Today,即 19/11/2009 22:00 UTC。
如何在不使用偏移量和夏令时计算的情况下做到这一点?
您可以使用TimeZoneInfo.ConvertTime。这是 .NET 3.5 中的新功能。
尝试:
var zone = TimeZoneInfo.GetSystemTimeZones().First(tz => tz.StandardName == DesiredTimeZoneName);
Debug.WriteLine(new DateTimeOffset(DateTime.UtcNow.Date.Ticks, zone.BaseUtcOffset).ToUniversalTime());
AFAIK,没有其他方法可以做到这一点。