判断两个日期是否同一天
NSCalendar *calendar = [NSCalendar currentCalendar];
unsigned unitFlags = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay;
// 要比较的那个日期,NSDate类型
NSDateComponents* comp1 = [calendar components:unitFlags fromDate:createOrderTime];
// 跟现在的时间相比
NSDateComponents* comp2 = [calendar components:unitFlags fromDate:now];
BOOL isSameDay = [comp1 day] == [comp2 day] && [comp1 month] == [comp2 month] && [comp1 year] == [comp2 year];
网友评论