iOS API TimeZone.current 不是 return 实际系统时间

iOS API TimeZone.current does not return actual system time

我的 iOS swift 应用调用 TimeZone.current 当应用程序来到前台时。如果我从“设置”->“常规”->“日期和时间”手动更改时区,然后将我的应用程序带到前台,我会得到正确的时区。但是如果我的时区设置设置为自动,然后我关闭自动,并将我的应用程序带回前台,TimeZone.current API 不会反映新的系统时区!

如果我将应用程序置于后台并再次回到前台,这一次它反映了正确的系统时区。 这是 iOS SDK 中的错误吗?有解决办法吗?

尝试使用 NSTimeZone.local,即:

An object that tracks the current system time zone.

您也可以使用 NSTimeZone.system 属性,但您需要手动调用 NSTimeZone.resetSystemTimeZone() 来清除和刷新当前缓存的系统时区值。