I have to elaborate a date with dateComponents:
int year;
int month;
int day;
int hour;
int minute;
int second;
NSCalendar *calendar;
NSDate *actualDate;
NSDate *itemDate;
NSDateComponents *dateComps;
NSDateFormatter *dateFormatter;
UILocalNotification *sveglia;
actualDate = [NSDate date];
calendar = [[NSCalendar currentCalendar] copy];
dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setTimeZone:[calend开发者_Python百科ar timeZone]];
[dateFormatter setDateFormat:@"yyyy"];
year = [[dateFormatter stringFromDate:actualDate] intValue];
[dateFormatter setDateFormat:@"MM"];
month = [[dateFormatter stringFromDate:actualDate] intValue];
[dateFormatter setDateFormat:@"dd"];
day = [[dateFormatter stringFromDate:actualDate] intValue];
[dateFormatter setDateFormat:@"HH"];
hour = [[dateFormatter stringFromDate:actualDate] intValue];
[dateFormatter setDateFormat:@"mm"];
minute = [[dateFormatter stringFromDate:actualDate] intValue];
[dateFormatter setDateFormat:@"ss"];
second = [[dateFormatter stringFromDate:actualDate] intValue];
dateComps = [[NSDateComponents alloc] init];
[dateComps setTimeZone:[calendar timeZone]];
[dateComps setDay:day];
[dateComps setMonth:month];
[dateComps setYear:year];
[dateComps setHour:hour];
[dateComps setMinute:minute];
// Obtaining date from components.
itemDate = [calendar dateFromComponents:dateComps];
NSLog(@"ItemDate: %@", itemDate);
calendar has the correct TimeZone, all the components of the Date are rights. Well, no matter what I do, itemDate object has the Greenwich TimeZone (+0000). How should I fix this problem?
Solved... The problem did not exists since the moment that the date was correct, the NSDate description give always the output in GMT time. To see the correct format you should use descriptionWithLocale, check the documentation for this one.
Source
精彩评论