开发者社区> 问答> 正文

判断是否是当前日期,是哪里出问题了呢?

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
//这两个日期不是不一样的吗?为什么结果为真呢?

展开
收起
a123456678 2016-07-28 10:41:36 1814 0
1 条回答
写回答
取消 提交回答
  • date 属性返回的是NSDate类型…… 而不是日期……

    可以把controllerComps.date == nowComps.date改成:controllerComps.day == nowComps.day 如果你一定要这么比较的话。

    2019-07-17 20:01:10
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载