设为首页 加入收藏

TOP

【代码笔记】iOS-两个时间字符串的比较
2017-10-13 10:24:06 】 浏览:7071
Tags:代码 笔记 iOS- 两个时间 字符串 比较

一,效果图。

二,代码。

复制代码
- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self initTimerCompare];
    
}
#pragma -mark -functions
//比较时间
-(void)initTimerCompare
{
    
    NSString *starTimer=@"2014-08-29";
    NSString *finishTimer=@"2014-09-30";
    
    BOOL result = [starTimer compare:finishTimer] == NSOrderedSame;
    NSLog(@"result:%d",result);
    if (result==1) {
        UIAlertView *alert=[[UIAlertView alloc]initWithTitle:nil message:@"开始时间和结束时间相等" delegate:self cancelButtonTitle:@"知道了" otherButtonTitles:nil, nil];
        [alert show];
        return;
    }
    
    BOOL result1 = [starTimer compare:finishTimer]==NSOrderedDescending;
    NSLog(@"result1:%d",result1);
    if (result1==1) {
        UIAlertView *alert=[[UIAlertView alloc]initWithTitle:nil message:@"开始时间晚于结束时间" delegate:self cancelButtonTitle:@"知道了" otherButtonTitles:nil, nil];
        [alert show];
        return;
    }

    
    BOOL result2 = [starTimer compare:finishTimer]==NSOrderedAscending;
    NSLog(@"result2:%d",result1);
    if (result2==1) {
        UIAlertView *alert=[[UIAlertView alloc]initWithTitle:nil message:@"开始时间早于结束时间" delegate:self cancelButtonTitle:@"知道了" otherButtonTitles:nil, nil];
        [alert show];
        return;
    }

}
复制代码

 

 

 
 
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇IOS 二维码生成 下一篇简述AFN(AFNetWorking 2.X)的实..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目