zoukankan      html  css  js  c++  java
  • 比较两个日期的前后顺序

        
    
     NSString * deliverydate = dicUrl[@"deliverydate"];           
     NSString * arrivedate = dicUrl[@"arrivedate"];
    
     if (![self compareDate:deliverydate withDate:arrivedate]) {
             [self createUIAlertController:@"送达日期不能小于发车日期"];
      }
    
    -(BOOL)compareDate:(NSString*)date01 withDate:(NSString*)date02{
        
        NSDateFormatter *df = [[NSDateFormatter alloc] init];
        [df setDateFormat:@"yyyy-MM-dd"];
        NSDate *dt1 = [[NSDate alloc] init];
        NSDate *dt2 = [[NSDate alloc] init];
        dt1 = [df dateFromString:date01];
        dt2 = [df dateFromString:date02];
        NSComparisonResult result = [dt1 compare:dt2];
        switch (result)
        {
                //date02比date01大
            case NSOrderedAscending: return YES; break;
                //date02比date01小
            case NSOrderedDescending: return NO; break;
                //date02=date01
            case NSOrderedSame: return YES; break;
            default: NSLog(@"erorr dates %@, %@", dt2, dt1); break;
        }
    }
    
    -(void)createUIAlertController:(NSString*)title
    {
        UIAlertController * alert =[UIAlertController alertControllerWithTitle:@"提示" message:title preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction * action =[UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            
        }];
        UIAlertAction * action1 =[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        }];
        [alert addAction:action1];
        [alert addAction:action];
        [self presentViewController:alert animated:YES completion:nil];
    }

  • 相关阅读:
    012 spring retry重试原理的解析
    011 @Retryable的使用
    010 @ControllerAdvice
    009 SpringBoot+Swagger的使用
    008 @Import作用
    007 SpringBoot的@EnableAutoConfiguration注解
    001 品牌管理案例
    000 vue各种基本指令
    013 JS
    002 docker基本的命令
  • 原文地址:https://www.cnblogs.com/sayimba/p/5694112.html
Copyright © 2011-2022 走看看