如果我在C#控制台应用程序中执行此代码,它可以正常工作.
TimeZoneInfo easternZone = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");
Console.WriteLine(easternZone.DisplayName);
Run Code Online (Sandbox Code Playgroud)
但是,当我在Unity应用程序中使用相同的方法时,会抛出异常:
System.TimeZoneNotFoundException: Exception of type 'System.TimeZoneNotFoundException' was thrown.
at System.TimeZoneInfo.FindSystemTimeZoneByFileName (System.String id, System.String filepath) [0x00000] in <filename unknown>:0
at System.TimeZoneInfo.FindSystemTimeZoneById (System.String id) [0x00000] in <filename unknown>:0
...
Run Code Online (Sandbox Code Playgroud)
我注意到的一个奇怪的事情是,当MSDN文档明确表示从注册表中检索信息时,会在名为"FindSystemTimeZoneByFileName"的方法中抛出异常.