Solved

Objective C code question

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

760 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

26 Experts available now in Live!

Get 1:1 Help Now