NSLog(@"%@ - %@ - %@",currTime,sunrise,sunset);
NSString *curtime = [[currTime substringToIndex:(currTime.length-4)] stringByAppendingString:@"-0000"];
NSDateFormatter *formatter1 = [[NSDateFormatter alloc]init];
NSLocale *locale = [[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]autorelease];
[formatter1 setDateFormat:@"EEE, dd MMM yyyy h:mm aZ"];
[formatter1 setLocale:locale];
NSDate *time = [formatter1 dateFromString:curtime];
[formatter1 setDateFormat:@"EEE dd MMM yyyy"];
NSString *zone = [formatter1 stringFromDate:time];
NSString *r = [sunrise stringByAppendingString:zone];
NSString *s = [sunset stringByAppendingString:zone];
[formatter1 setDateFormat:@"hh:mm aEEE dd MMM yyyy"];
NSDate *rise = [formatter1 dateFromString:r];
NSDate *set = [formatter1 dateFromString:s];
unsigned int flags = NSHourCalendarUnit | NSMinuteCalendarUnit | NSDayCalendarUnit;
NSCalendar *calendar = [NSCalendar currentCalendar];
NSDateComponents *components1 = [calendar components:flags fromDate:rise];
NSDateComponents *components2 = [calendar components:flags fromDate:set];
NSDateComponents *components3 = [calendar components:flags fromDate:time];
NSInteger riseHour = [components1 hour];
NSInteger setHour = [components2 hour];
NSInteger timeHour = [components3 hour];
NSLog(@"\nSunrise: %@ \nSunset: %@ \nCurrent: %@",rise,set,time);
NSLog(@"Rise: %i Set: %i Time: %i",riseHour,setHour,timeHour);
Я ожидаю, что это сработает.Тем не менее, посмотрите на вывод ниже:
Вс, 12 июня 2011 года, 1:54 утра CDT - 6:33 утра - 20:34
Восход солнца: 2011-06-11 21:33: 00 +0000
Закат: 2011-06-12 11:34:00 +0000
Текущий: 2011-06-12 01:54:00 +0000
Повышение: 6 <правильно </p>
Набор: 20 <правильно </p>
Время: 10 <неправильно </p>