iOS当前时间和后台返回时间做比较大小
2017-06-14 08:50
585 查看
#pragma mark -得到当前时间 - (NSDate *)CurrentTime{ NSDateFormatter *formatter=[[NSDateFormatter alloc]init]; //当前时间格式 [formatter setDateFormat:@"yyyy-MM-dd"]; NSString *dateTime=[formatter stringFromDate:[NSDate date]]; NSDate *date = [formatter dateFromString:dateTime]; NSLog(@"---------- currentDate == %@",date); return date; } #当前时间和后台返回的时间比较方法,返回一个int类型的数据 //oneDay:当前时间 //anotherDay:返回时间 - (int)compareCurrentTimeDay:(NSDate *)oneDay withAnotherDay:(NSDate *)anotherDay { NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; //这个时间格式需要和当前得到时间格式相同才能做比较 [dateFormatter setDateFormat:@"yyyy-MM-dd"]; NSString *oneDayStr = [dateFormatter stringFromDate:oneDay]; NSString *anotherDayStr = [dateFormatter stringFromDate:anotherDay]; NSDate *dateA = [dateFormatter dateFromString:oneDayStr]; NSDate *dateB = [dateFormatter dateFromString:anotherDayStr]; NSComparisonResult result = [dateA compare:dateB]; NSLog(@"date1 : %@, date2 : %@", oneDay, anotherDay); if (result == NSOrderedDescending) { //NSLog(@"Date1 is in the future"); //当前时间大于返回时间 return 1; } else if (result == NSOrderedAscending){ //NSLog(@"Date1 is in the past"); //当前时间小于返回时间 return -1; } //NSLog(@"Both dates are the same"); //完全相等(NSOrderedDescending,NSOrderedAscending,NSOrderedSame这三个是一个枚举类型) return 0; }
相关文章推荐
- 返回行javascript比较时间大小
- IOS比较两个日期的大小获取当前月份天数(今天、明天、后天)
- 比较当前时间和给定时间大小
- iOS 时间比较大小
- 时间加上偏移量于当前时间比较大小 java实现
- ios返回当前时间,精确到毫秒。
- 两个时间比较大小,结束日期不能大于起始日期,起始日期不能大于当前日期
- iOS NSDate比较返回差多少时间
- IOS 在当前日期时间加上 某个时间段(传负数即返回当前时间之前x月x日的时间)
- ios返回当前时间,精确到毫秒。
- jquery获取当前系统时间+js两个时间的大小比较
- CT时间与当前时间的大小比较
- iOS比较当前日期与指定日期大小
- JS 和当前时间比较大小
- 字符串转换成时间格式,并与本时区当前时间,比较大小。
- jquery 时间大小比较和获取当前时间
- js正则表达式具体时间的验证,当前日期跟所填日期比较大小,时间的比较
- JSP 比较时间字段与当前时间大小进行相关显示
- C# 比较时间大小返回整形函数
- 比较当前时间和给定时间大小