當前日期不應該在開始日期去結束日期後,但它可以等於開始日期或結束日期。檢查今天的日期開始日期和結束日期之間落在
我該如何修改代碼?
for(AllBookings *book in bookarray)
{
NSString *startdte = book.StartDate; //taking start date from array
NSString *enddte = book.EndDate;
NSDate *start = [self getDateFromJSON:startdte];
NSDate *end = [self getDateFromJSON:enddte];
NSDate *now = [NSDate date];
NSTimeInterval fromTime = [start timeIntervalSinceReferenceDate];
NSTimeInterval toTime = [end timeIntervalSinceReferenceDate];
NSTimeInterval currTime = [[NSDate date] timeIntervalSinceReferenceDate];
if((fromTime<currTime) && (toTime>=currTime))//checking if currnt is in btw strt n end
{
success = TRUE;
break;
}
else {
success = FALSE;
}
}
在這裏檢查你發現許多完全相同的問題。 –
檢查此鏈接http://stackoverflow.com/questions/6112075/ios-compare-two-dates – Durgaprasad