0

ANy idea why this code output "2011-11-30 23:00:00 +0000" instead "2011-12-01 00:00:00 +0000"

NSDateComponents *minDateComponents = [[NSDateComponents alloc] init];
[minDateComponents setYear:2011];
[minDateComponents setMonth:12];
[minDateComponents setDay:1];
[minDateComponents setHour:00];
[minDateComponents setMinute:00];
[minDateComponents setSecond:0];
[minDateComponents setTimeZone:nil];

NSLog(@"%@",[[NSCalendar currentCalendar] dateFromComponents:minDateComponents]);
Marcin
  • 3,694
  • 5
  • 32
  • 52

1 Answers1

0

You need to set the NSDateComponent timeZone property to match your NSCalendar timeZone property. You could, for example, set them both to

[NSTimeZone systemTimeZone];

or

[NSTimeZone localTimeZone];
jbat100
  • 16,757
  • 4
  • 45
  • 70