Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Objective C code question

Posted on 2012-03-20
1
Medium Priority
?
536 Views
Last Modified: 2016-02-10
Hi,
I'm working my way through a book on Obj C. Please look at the code below and my explanation and tell me why my results are not the same with using the Class and Instance methods.
---
If I use the class method of systemTimeZone it's telling me (I think) that I am on Daylight savings time.
However, If I use an instance method for isDaylightSavingTime I am getting a 0 returned.
Help?

Thanks

nacht

#import <Foundation/Foundation.h>

int main (int argc, const char * argv[])
{

NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];





NSTimeZone *zone = [[NSTimeZone alloc] init]; // Create an instance

NSTimeZone *c = [NSTimeZone systemTimeZone]; // Class method so don't need to create an instance

NSLog(@"Time zone is %@\n", c);

BOOL z =[zone isDaylightSavingTime];


NSLog(@"Is it set to Daylight Savings time: %d\n", z);


[pool drain];
return 0;
}


OUTPUT:
2012-03-20 11:05:02.525 TimeZone[1259:903] Time zone is US/Eastern (EDT) offset -14400 (Daylight)
2012-03-20 11:05:02.526 TimeZone[1259:903] Is it set to Daylight Savings time: 0
0
Comment
Question by:nachtmsk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 6

Accepted Solution

by:
leuqarte earned 2000 total points
ID: 37813813
NSTimeZone *c = [NSTimeZone systemTimeZone]; 

Open in new window

works as expected...

NSTimeZone *zone = [[NSTimeZone alloc] init];

Open in new window

creates a time zone object but isn't set to current system time zone automatically.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

CocoaPods is the best way to manage library dependencies in iOS and OS X projects. By using cocoa pods there is no need of downloading the code from github and copying to your project. There are plenty of open source libraries now available with C…
Do you come here a lot? Are you lazy like me and don't want to go through the "trouble" of having to click your Dock's Safari icon and then having to click your Experts Exchange Favorites bookmark to get here? Well then this article is for you.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question