我觉得这是一个非常简单的问题,以前肯定有人遇到过这个问题。要么我想不出正确的搜索关键字,要么没有人真正遇到过这个问题。
我的问题是,当我进入 Windows 系统时间并更改时区时,系统托盘时间会相应更新,但我正在运行的应用程序似乎完全没有注意到这一事实。我尝试过的所有 .NET 对象似乎都没有反射(reflect)系统时区已更改的事实。我在之前和之后检查了以下对象,看看它们是否发生了变化:
DateTime.Now;
DateTime.Now.Offset;
TimeZone.CurrentTimeZone.StandardName;
对我来说,时区会在应用程序的同一电源循环中发生变化,这对我来说是一个非常小的案例,但无论如何,我必须解决它。有没有办法告诉 .NET 框架“刷新您的时区”或其他什么?
查看该属性的文档:
http://msdn.microsoft.com/en-us/library/system.timezone.currenttimezone(v=vs.110).aspx
Local time zone data is cached after CurrentTimeZone is first used to retrieve time zone information. If the system's local time zone subsequently changes, the CurrentTimeZone property does not reflect this change. If you need to handle time zone changes while your application is running, use the TimeZoneInfo class and call its TimeZoneInfo.ClearCachedData method.
TimeZoneInfo local = TimeZoneInfo.Local;
TimeZoneInfo.ClearCachedData();
local = TimeZoneInfo.Local; //updated local time zone info