NSTimeZone:localTimeZone 和 systemTimeZone 有什么区别? [英] NSTimeZone: what is the difference between localTimeZone and systemTimeZone?

查看:28
本文介绍了NSTimeZone:localTimeZone 和 systemTimeZone 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 NSTimeZone 类下,有 +localTimeZone 和 +systemTimeZone.我在 iphone 模拟器上做了一个测试,都返回 NSTimeZone 对象,指示相同的时区.有什么区别?我应该使用哪一个来找出 iPhone 的时区设置?谢谢

Under NSTimeZone class, there is both +localTimeZone and +systemTimeZone. I did a test on iphone simulator, both return NSTimeZone object indicating the same timezone. What is the difference? Which one I should use to find out the timezone setting of the iPhone? Thanks

我的测试:

NSLog(@"Local Time Zone %@",[[NSTimeZone localTimeZone] name]);
NSLog(@"System Time Zone %@",[[NSTimeZone systemTimeZone] name]);

推荐答案

用户(或您的应用程序或其他应用程序)可以更改应用程序的默认时区(使用 +[NSTimeZone setDefaultTimeZone]) 或系统时区(使用系统偏好设置).+[NSTimeZone localTimeZone] 返回一个代理,该代理将始终充当应用程序的当前默认时区,即使该默认值发生变化.您可以更改应用程序的默认时区,使其表现得就像在不同的时区一样.

The user (or your application or an other application) may change either the default time zone for an application (using +[NSTimeZone setDefaultTimeZone]) or the system time zone (using System Preferences) at any time. +[NSTimeZone localTimeZone] returns a proxy that will always act as if it is the current default time zone for the application, even if that default changes. You could change the default time zone for an application to make it behave as if it were in a different time zone.

+[NSTimeZone systemTimeZone] 返回当前 系统时区(使用系统偏好设置).在大多数情况下,这些都是相同的(我相信应用的默认时区设置为应用启动时的系统时区).

+[NSTimeZone systemTimeZone] returns the current system time zone (as set using System Preferences). In most cases, these will be the same (the app's default time zone is set to the system time zone at app startup, I believe).

如果你想知道系统的时区设置,你可能想使用+[NSTimeZone systemTimeZone].如果您只想让您的应用使用正确的时区,您可能需要 +[NSTimeZone localTimeZone].

If you want to know the system's time zone setting, you probably want to use +[NSTimeZone systemTimeZone]. If you just want the correct time zone for your app to work in, you probably want +[NSTimeZone localTimeZone].

这篇关于NSTimeZone:localTimeZone 和 systemTimeZone 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆