controllerComps:视图控制器的NSDateComponents指针;
nowComs:当前日期的NSDateComponents指针
BOOL isToday = ((controllerComps.year == nowComps.year)&&(controllerComps.month == nowComps.month)&&(controllerComps.date == nowComps.date));
NSLog(@"isToday:%hhd",isToday);
以下为打印内容:
2015-03-19 14:59:58.267 Playing-higherExercise[6423:1141331] nowComps:
Calendar Year: 2015
Month: 3
Leap month: no
Day: 19
2015-03-19 14:59:58.268 Playing-higherExercise[6423:1141331] controllerComps:
Calendar Year: 2015
Month: 3
Leap month: no
Day: 18
2015-03-19 14:59:58.269 Playing-higherExercise[6423:1141331] isToday:1
//这两个日期不是不一样的吗?为什么结果为真呢?
date
属性返回的是NSDate
类型…… 而不是日期……可以把
controllerComps.date == nowComps.date
改成:controllerComps.day == nowComps.day
如果你一定要这么比较的话。