Solved

Objective C code question

Posted on 2012-03-20
1
512 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
1 Comment
 
LVL 6

Accepted Solution

by:
leuqarte earned 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Preface   In the first 100 days of the Macintosh release in January 1984, Apple sold 72,000 of the computers. Relatively cheap, easy-to-use personal computer with a graphical operating system. I've never seen this model. I did see this one:   …
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.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

863 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now