DST에 매우주의하십시오. 다양한 시간대에 따라 다릅니다. 그리고 자정에 발생합니다 [NSCalendar 날짜 추가] : [날짜 : 옵션]을 호출하고 날짜가 오후 11-12시 사이라면 DST로 인해 하루가 누락되거나 재실행 될 위험이 있습니다. 이 문제를 해결하려면 날짜를 정오로 변경하고 요일을 추가하는 것이 좋습니다.
// increment by 1 calendar day
// and convert back to NSDate objects
NSDateComponents *comps = [[[NSDateComponents alloc] init] autorelease];
[comps setDay:1];
NSCalendar *gregorian = [[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar] autorelease];
[gregorian setTimeZone:self.myTimeZone]; // time zone of location;
// Use local noontime for the date to avoid problems around
// midnight, particularly near daylightsavings time discontinuities.
NSUInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit;
NSDateComponents* dateComponents = [gregorian components:unitFlags fromDate:date];
dateComponents.hour = 12;
NSDate* noonDate = [gregorian dateFromComponents:dateComponents];
NSDate *newDate = [gregorian dateByAddingComponents:comps toDate:noonDate options:0];
옵션 : 0 설정에 대해 확실하지 않지만이 테스트를 철저히 테스트했습니다. 10 일간의 날짜 배열을 얻으 려합니다. 그것은 다양한 일/월/년 불연속 주위에 올바른 포장을 제공합니다. 테스트하려는 경우 SunPose Rise Set를 앱 스토어에서 확인하십시오. (예, 무료입니다)
출처
2011-10-01 08:51:24
Suz
쿨, 고마워요 - 내 코드에서이 버그를 알려준 트위터 야 btw : P –