我有以下要求,
下面是使用但不起作用的代码,
- (IBAction)timePicker:(id)sender {
selectedTimeRow = [sender tag];
NSDate *date2=[NSDate date];
NSDate *DaysAgo;
if (selectedTimeRow==0) {
DaysAgo = [date2 dateByAddingTimeInterval:14*24*60*60];
NSLog(@"14 days ago: %@", DaysAgo);
}else if (selectedTimeRow==1){
DaysAgo = [date2 dateByAddingTimeInterval:7*24*60*60];
NSLog(@"7 days ago: %@", DaysAgo);
}else if (selectedTimeRow==2){
DaysAgo = [date2 dateByAddingTimeInterval:3*24*60*60];
NSLog(@"3 days ago: %@", DaysAgo);
}else if (selectedTimeRow==3){
DaysAgo = [date2 dateByAddingTimeInterval:1*24*60*60];
NSLog(@"1 days ago: %@", DaysAgo);
}
NSDateFormatter *format = [[NSDateFormatter alloc] init];
format.dateFormat = @"dd/MM/yyyy";
NSString *dateNew=[format stringFromDate:DaysAgo];
UIButton *button = (UIButton *)sender;
UITableViewCell *cell = (UITableViewCell*)[button superview];
//
NSComparisonResult result = [dateNew compare:_SavedDate];
if(result == NSOrderedAscending)
{
NSLog(@"date1 is later than date2");
cell.userInteractionEnabled=NO;
}else if (result == NSOrderedDescending) {
NSLog(@"date1 is earlier than date2");
[self calltoolrBar];
cell.userInteractionEnabled=YES;
}
else
{
NSLog(@"date1 is equal to date2");
[self calltoolrBar];
cell.userInteractionEnabled=YES;
}
}
答案 0 :(得分:-1)
两周前约会
NSDate * selecteDate = YOUR_DATE; NSDate * twoWeeksAgoDate = [selecteDate dateByAddingTimeInterval:-14 * 24 * 60 * 60]; // -14是14天(2周)之前。你需要根据自己的意愿改变。 NSLog(@"两周前:%@",twoWeeksAgoDate);
为twoWeeksAgo Date设置本地通知
UILocalNotification * notification = [[UILocalNotification alloc] init]; notification.repeatInterval = NSDayCalendarUnit; [notification setAlertBody:@" Your Reminder"]; [notification setFireDate:twoWeeksAgoDate]; [notification setTimeZone:[NSTimeZone defaultTimeZone]]; [application setScheduledLocalNotifications:[NSArray arrayWithObject:notification]];