NSDate *date = [NSDate date];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc]init];
[dateFormat setDateFormat:@"MM/dd/yyyy"];
NSLog([@"today is " stringByAppendingString:[dateFormat stringFromDate:date]]);
NSLog([@"firstBirthdayDate is " stringByAppendingString:[dateFormat stringFromDate:firstBirthdayDate]]);
NSLog([@"secondBirthdayDate is " stringByAppendingString:[dateFormat stringFromDate:secondBirthdayDate]]);
if ([firstBirthdayDate isEqualToDate:secondBirthdayDate])
NSLog(@"First date is the same as second date");
if (firstBirthdayDate < date)
NSLog(@"First date is earlier than today");
else
NSLog(@"First date is later than today");
if (secondBirthdayDate < date)
NSLog(@"Second date is earlier than today");
- 今天是 11/08/2012
firstBirthdayDate
是 2012 年 1 月 23 日secondBirthdayDate
是 2012 年 1 月 23 日
这是我在日志中得到的:
第一个日期与第二个日期相同
第一个日期晚于今天
第二个日期早于今天
我想我要疯了...