잘못된 날짜가 표시되는 이유는 무엇입니까?NSDateComponents에서 잘못된 날짜가 반환됩니다.
NSCalendar *myCalendar = [[NSCalendar alloc] initWithCalendarIdentifier: NSGregorianCalendar];
NSDateComponents* components = [myCalendar components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit fromDate:[NSDate date]];
[components setYear:2013];
[components setMonth:06];
[components setDay:28];
[components setHour:5];
[components setMinute:00];
NSDate *startDate1 = [myCalendar dateFromComponents:components];
NSLog(@"start date is %@",startDate1);
시작 날짜는 내가하고 싶은 것은 다음과 같다 편집
2013년 6월 28일 3시 0분 0초 0000
입니다. 나는 시작과 끝이있다. 2013년 6월 28일 5시
종료 날짜는
시작 날짜 : 예를 들어
이 2013년 6월 29일 4시 59분
그럼 내가 현재 여부를 확인하려면 날짜는 시작일과 종료일 사이입니다. 나는 다음을 사용하고있다.
NSComparisonResult result1 = [now compare:startDate1];
NSComparisonResult result2 = [now compare:endDate1];
if (result2 == NSOrderedSame && result1 == NSOrderedSame) {
NSLOG(@"OKE!");
}
당신의 날짜 값은 시간대에 따라 달라집니다. 문제를 해결할 현지 시간대로 변경하십시오. 설정 - 일반 - 날짜 및 시간. – brianLikeApple