两个时间字符串的比较
【摘要】 - (void)viewDidLoad{ [super viewDidLoad]; // Do any additional setup after loading the view. [self initTimerCompare]; }#pragma -mark -functions//比较时间-(void)initTimerCompare{ ...
- (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;
}
}
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)