首页 > 其他 > 详细

【代码笔记】两个时间字符串的比较

时间:2016-04-21 10:10:28      阅读:129      评论:0      收藏:0      [点我收藏+]

一,效果图。

技术分享

二,代码。

技术分享
- (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;
    }

}
技术分享

 

 

 
 

【代码笔记】两个时间字符串的比较

原文:http://www.cnblogs.com/yang-guang-girl/p/5415685.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!