在WPF/C#中显示时区.发现夏令时抵消

dis*_*rax 2 c# wpf timezone datetime

我无法理解系统注册表如何帮助我将DateTime对象转换为相应的TimeZone.我有一个例子,我一直在尝试进行逆向工程,但我根本不能按照夏令时来跟踪UTCtime偏移的一个关键步骤.

我正在使用.NET 3.5(感谢上帝),但它仍然令我困惑.

谢谢

编辑:附加信息:此问题用于WPF应用程序环境.我在下面留下的代码片段将答案示例更进一步,以获得我正在寻找的内容.

dis*_*rax 9

这是我在我的WPF应用程序中使用的C#中的代码片段.这将为您提供您提供的时区ID的当前时间(根据夏令时调整).

// _timeZoneId is the String value found in the System Registry.
// You can look up the list of TimeZones on your system using this:
// ReadOnlyCollection<TimeZoneInfo> current = TimeZoneInfo.GetSystemTimeZones();
// As long as your _timeZoneId string is in the registry 
// the _now DateTime object will contain
// the current time (adjusted for Daylight Savings Time) for that Time Zone.
string _timeZoneId = "Pacific Standard Time";
DateTime startTime = DateTime.UtcNow;
TimeZoneInfo tst = TimeZoneInfo.FindSystemTimeZoneById(_timeZoneId);
_now = TimeZoneInfo.ConvertTime(startTime, TimeZoneInfo.Utc, tst);
Run Code Online (Sandbox Code Playgroud)

这是我最终得到的代码snippit.谢谢您的帮助.