두 날짜 간의 시간 간격이 3 개월보다 큰지 확인하고 있지만 성공하지 못했습니다. 여기 제가 시도하고있는 것이 있습니다. 내가 뭔가 잘못하고 있니? 어제 detailTextDate를 설정하더라도 evaluationLabel은 계속 표시됩니다. dateFormat을 설정해야합니까?iOS의 날짜 비교
NSString *detailTextDate = @"August 11, 2013";
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateStyle = NSDateFormatterLongStyle;
NSDate *startDate = [dateFormatter dateFromString:detailTextDate];
[dateFormatter setDateFormat:@"yyyy-MM-dd hh:mm:ss"];
NSDate *todaysDate = [NSDate date];
NSCalendar *gregorianCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *components = [gregorianCalendar components:NSMonthCalendarUnit
fromDate:startDate
toDate:todaysDate
options:0];
if(components.month >= 3){
evaluationLabel.hidden = NO;
}
}
//tried using NSYearCalendarUnit, Month, Day etc.
//startDate = 2013-08-11 06:00:00 +0000, detailTextDate = August 11, 2013, components = //<NSDateComponents: 0x176c3c70>
// Month: 0
했다? –
90 일이 아니라 실제 달에 관심이 있으십니까? –
@IanHenry : 3 개월, 90 일, 초, 밀리 초일 수 있습니다. 시간은 여전히 동등한 한 중요하지 않습니다. 나는 또한 며칠 안에 그것을 시도했다. –