Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The language in the docs is a bit on the dry side, to be sure, and the similarity of the names is potentially confusing. I'll quote the <a href="http://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSTimeZone_Class/"><code>NSTimeZone</code> docs</a> here and try to explain them:</p> <blockquote> <p><strong><code>systemTimeZone</code></strong><br> The time zone currently used by the system. If the current time zone cannot be determined, returns the GMT time zone.</p> </blockquote> <p>This is the time zone which the device believes it is in; it is often set automatically, and would then correspond to the device's physical location, but if the user has explicitly set a particular time zone in the Settings App, that's what you'll get.</p> <blockquote> <p><strong><code>defaultTimeZone</code></strong><br> The default time zone for the current application. If no default time zone has been set, this method invokes <code>systemTimeZone</code> and returns the system time zone.</p> </blockquote> <p>Your application is allowed to set its own time zone, so that you can perform actions as if the device were in another zone, but without affecting the system time zone (and thereby other apps). The setting is performed with a call to <code>setDefaultTimeZone:</code>. If you haven't done that, this call is identical to calling <code>systemTimeZone</code>.</p> <blockquote> <p><strong><code>localTimeZone</code></strong><br> An object that forwards all messages to the default time zone for the current application. The local time zone represents the current state of the default time zone at all times.</p> </blockquote> <p>This is where it gets a little bit tricky. <code>localTimeZone</code> gives you nearly the same result as <code>defaultTimeZone</code>. The difference is that the specific <code>NSTimeZone</code> instance you get from <code>localTimeZone</code> will always reflect the setting you've made to the time zone within your app. You can call it once, save the result, and always get the current simulated time zone through that object, no matter the changes made. It is as if, when you use this <code>NSTimeZone</code> instance, the framework is calling <code>defaultTimeZone</code> for you, to be sure that you always get the current value.</p> <p>Here's a couple of brief illustrations of the above. The <code>NSTimeZone</code> object that you get back from <code>systemTimeZone</code> represents the system time zone at the time you make the call. If you call <code>systemTimeZone</code> again, even if the user has since changed the time zone, you will get the same one. Your app caches that value, and you have to ask the system to clear it with <code>resetSystemTimeZone</code> to get the update.</p> <pre><code>// Say that device is in GMT originally NSLog(@"%@", [NSTimeZone systemTimeZone]); // GMT // User flies into Rome and iPhone changes the zone automatically NSLog(@"%@", [NSTimeZone systemTimeZone]); // Still GMT [NSTimeZone resetSystemTimeZone]; // Clear app's cache NSLog(@"%@", [NSTimeZone systemTimeZone]); // Now GMT+2 </code></pre> <p>A similar thing happens with <code>defaultTimeZone</code>. When you call that method, you get an object that will always represent the same time zone, even if you later call <code>setDefaultTimeZone:</code>. However, if you use the object you get from <code>localTimeZone</code>, it will follow the change you make to the default time zone*.</p> <pre><code>// Say that defaultTimeZone is originally GMT NSTimeZone * myDefaultTZ = [NSTimeZone defaultTimeZone]; NSTimeZone * myLocalTZ = [NSTimeZone localTimeZone]; [NSTimeZone setDefaultTimeZone:[NSTimeZone timeZoneWithName:@"Etc/GMT-4"]]; NSLog(@"%@", myDefaultTZ); // Still gives GMT NSLog(@"%@", [NSTimeZone defaultTimeZone]); // GMT-4, the new value NSLog(@"%@", myLocalTZ); // Also the new value! </code></pre> <p>Apple seems to <a href="http://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/DatesAndTimes/Articles/dtTimeZones.html#//apple_ref/doc/uid/20000185-SW2">recommend using</a> <code>localTimeZone</code>:</p> <blockquote> <p>with the localTimeZone class method, you can get a relative time zone object that decodes itself to become the default time zone on any computer on which it finds itself. </p> </blockquote> <hr> <p><sub>*Note that <code>localTimeZone</code> is still subject to the app-level cache of the system time zone. It only changes to follow your setting of the <em>default</em> time zone.</sub></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload