这是我在我的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.谢谢您的帮助.
| 归档时间: |
|
| 查看次数: |
8046 次 |
| 最近记录: |