- (void)viewDidLoad {
[super
viewDidLoad];
NSString *d =
@"2015-03-05 23:59:59";
NSDateFormatter *format = [[NSDateFormatter
alloc]
init];
[format setDateFormat:@"yyyy:MM:dd HH:mm:ss"];
NSDate *date = [format
dateFromString:d];
NSLog(@"%i", [ViewController
isCurrentDay:date]);
}
// 判断两个时间是否是同一天
+ (BOOL)isCurrentDay:(NSDate *)aDate
{
if (aDate==nil)
return NO;
NSCalendar *cal = [NSCalendar
currentCalendar];
NSDateComponents *components = [cal
components:(NSCalendarUnitEra|NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay)
fromDate:[NSDate
date]];
NSDate *today = [cal
dateFromComponents:components];
components = [cal components:(NSCalendarUnitEra|NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay)
fromDate:aDate];
NSDate *otherDate = [cal
dateFromComponents:components];
if([today isEqualToDate:otherDate])
return YES;
return
NO;
}