• ios日期比较


     1 +(int)compareDate:(NSDate *)date1 date:(NSDate *)date2
     2 {
     3     NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
     4     [dateFormatter setDateFormat:@"yyyy-MM-dd"];
     5      //比较准确度为“日”,如果提高比较准确度,可以在此修改时间格式
     6     NSString *stringDate1 = [dateFormatter stringFromDate:date1];
     7     NSString *stringDate2 = [dateFormatter stringFromDate:date2];
     8     NSDate *dateA = [dateFormatter dateFromString:stringDate1];
     9     NSDate *dateB = [dateFormatter dateFromString:stringDate2];
    10     NSComparisonResult result = [dateA compare:dateB];
    11     if (result == NSOrderedDescending) {
    12         return 1;  //date1 比 date2 晚
    13     } else if (result == NSOrderedAscending){
    14         return -1; //date1 比 date2 早
    15     }
    16     return 0; //在当前准确度下,两个时间一致
    17 }
  • 相关阅读:
    Django终端打印SQL语句
    Django之缓存
    Django总结三
    Django之信号
    Django之Form的ModelForm
    git下
    Ajax实现文件的上传
    operator模块
    Django之Form自定义验证规则
    New Concept English Two 32 88
  • 原文地址:https://www.cnblogs.com/wangshengl9263/p/3459099.html
Copyright © 2020-2023  润新知