我想要做的是使日期使用大于小于符号的if语句。出于某种原因,只有大于号的作品。这里是我的代码:如果声明的日期
NSDate *currDate = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
[dateFormatter setDateFormat:@"HHmm"];
NSString *dateString = [dateFormatter stringFromDate:currDate];
NSLog(@"%@",dateString);
if (dateString < @"0810" && dateString > @"0800") {
NSLog(@"Homeroom");
}
else {
NSLog(@"no");
}
此代码的输出是,如果时间为8:03:
2013-04-08 08:03:47.956 Schedule2.0[13200:c07] 0803
2013-04-08 08:03:47.957 Schedule2.0[13200:c07] no
如果我要提出的是这样的地方只有再签收,如更大这样的:
if (dateString > @"0800") {
NSLog(@"Homeroom");
}
else {
NSLog(@"no");
}
输出会是这样:
2013-04-08 08:03:29.748 Schedule2.0[14994:c07] 0803
2013-04-08 08:03:29.749 Schedule2.0[14994:c07] Homeroom
你可以举一个NSDate对象的例子,对不起我对客观的C ... – user2259486 2013-04-08 22:58:49
请看我的编辑。并检查日期和日历主题的苹果文档:执行日历计算不是微不足道的 – vikingosegundo 2013-04-08 23:03:11
我修复了一些错别字 – vikingosegundo 2013-04-08 23:04:39