NSDateFormatter *timeFormatter = [[NSDateFormatter alloc] init];
[timeFormatter setDateStyle:NSDateFormatterNoStyle];
[timeFormatter setTimeZone:[NSTimeZone localTimeZone]];
[timeFormatter setDateFormat:@"dd/MM/YYYY HH:mm"];
NSDate *startDate = [timeFormatter1 dateFromString:@"07/10/2015 12:30"];
NSDate *EndDate = [timeFormatter1 dateFromString:@"08/10/2015 02:30"];
if([startDate compare:EndDate] == NSOrderedAscending)
return YES;
else
return NO;
我跟隨上面的代碼,但每次輸出都是錯誤的結果(去「返回否」)。如何比較兩個日期和時間,EXP:07/10/2015 12:30至08/10/2015 02:00在ios中?
同時EXP:07/10/2015 12:30到07/10/2015 23:30這是工作。
我需要在一個時間兩種格式的工作。
請幫幫我嗎?
我認爲你錯了'timeFormatter1'。可能你錯過了'timeFormatter'。並且在startDate和EndDate中爲零。 –