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

查看:1686
本文介绍了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天全站免登陆