the following code
NSCalendar *cal = [NSCalendar currentCalendar];
[cal setFirstWeekday:2];
[cal setMinimumDaysInFirstWeek:4];
NSDateComponents *comp = [[NSDateComponents alloc] init];
[comp setYear: 2012];
[comp setMonth:3];
[comp setDay: 12];
NSDate *date = [cal dateFromComponents:comp];
NSLog(@"date:%@",date);
logs:
date:2012-03-11 23:00:00 +0000
Any Idea, why this happen and how to avoid
Tnx
I assume you are using the CET time zone locally. This is what the
[NSCalendar currentCalendar]will use as a time zone then.When you dump a
NSDatewith NSLog, you will get the date in its raw UTC form. To print the date using a local format, look into theNSDateFormatterclass, which has atimeZoneproperty: