Solved

Objective C code question

Posted on 2012-03-20
1
526 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 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

623 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