NSDate *date = [NSDate date];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
//获得系统当前日期
NSString *dString = [dateFormat stringFromDate:date];
NSDate *currentDate = [dateFormat dateFromString:dString];
//开始时间
NSString *startTime = self.startTime.text;
NSDate *startDate = [dateFormat dateFromString:startTime];
//结束时间
NSString *endTime = self.endTime.text;
NSDate *endData = [dateFormat dateFromString:endTime];
//计算时间间隔
NSTimeInterval secondsBetweenCurrentDateToStartDate = [currentDate timeIntervalSinceDate:startDate];
NSTimeInterval secondsBetweenCurrentDateToEndDate = [currentDate timeIntervalSinceDate:endData];
NSTimeInterval secondsBetweenStartToEndDate = [startDate timeIntervalSinceDate: endData];
//判断时间
if (secondsBetweenCurrentDateToStartDate > 0.000000) {
[SettingData alert:@"开始时间不能晚于当前时间!" delegeate:nil];
return;
}
if (secondsBetweenCurrentDateToEndDate > 0.000000) {
[SettingData alert:@"结束时间不能晚于当前时间!" delegeate:nil];
return;
}
if (secondsBetweenStartToEndDate >0.000000) {
[SettingData alert:@"开始时间不能晚于结束时间!" delegeate:nil];
return;
}