Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

RossOliver

macrumors regular
Original poster
Nov 6, 2006
157
0
Hello,

I'm getting very odd results when I NSLog an NSDate created with NSDateComponents:

Code:
NSDate *test;
NSDateComponents *comps = [[NSDateComponents alloc] init];
[comps setDay:26];
[comps setMonth:3];
[comps setYear:2012];
test = [[NSCalendar currentCalendar] dateFromComponents:comps];
NSLog(@"DAY: %i, MONTH: %i, YEAR: %i, DATE: %@", [test day], [test month], [test year], test);
// OUTPUTS: DAY: 26, MONTH: 3, YEAR: 2012, DATE: 2012-03-25 23:00:00 +0000

When you NSLog the NSDate this code produces, it outputs 2012-03-25, not 2012-03-26. However, if I set the components to a date prior to 2012-03-26, such as 2012-03-25, it works perfectly - outputting 2012-03-25 00:00:00. Any date after and including 26th March 2012 logs the date as the previous day with the hour portion set to 23:00:00. I can't for the life of me understand why?

Any help greatly appreciated!

Cheers

-Ross
 

quellish

macrumors newbie
Apr 19, 2010
4
0
Hello,

I'm getting very odd results when I NSLog an NSDate created with NSDateComponents:

Code:
NSDate *test;
NSDateComponents *comps = [[NSDateComponents alloc] init];
[comps setDay:26];
[comps setMonth:3];
[comps setYear:2012];
test = [[NSCalendar currentCalendar] dateFromComponents:comps];
NSLog(@"DAY: %i, MONTH: %i, YEAR: %i, DATE: %@", [test day], [test month], [test year], test);
// OUTPUTS: DAY: 26, MONTH: 3, YEAR: 2012, DATE: 2012-03-25 23:00:00 +0000

When you NSLog the NSDate this code produces, it outputs 2012-03-25, not 2012-03-26. However, if I set the components to a date prior to 2012-03-26, such as 2012-03-25, it works perfectly - outputting 2012-03-25 00:00:00. Any date after and including 26th March 2012 logs the date as the previous day with the hour portion set to 23:00:00. I can't for the life of me understand why?

Any help greatly appreciated!

Cheers

-Ross

Sounds like Daylight savings in the UK ;)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.