我正在开发一个应用程序,它涉及从日期选择器中获取值并从实际iphone上显示的日期中减去它。我该怎么做?我到处寻找答案!
谢谢Rafee
答案 0 :(得分:1)
您应该将datePickerValueChanged
实现为选择器,并按此实现。
- (void)datePickerValueChanged:(UIDatePicker*) date_Picker{
NSDateFormatter *df = [[NSDateFormatter alloc] init];
df.dateStyle = NSDateFormatterMediumStyle;
NSString *dateFromPicker = [NSString stringWithFormat:@"%@",[df stringFromDate:date_Picker.date]];
// calculating time difference now
NSDate *timeRightNow = [NSDate date];
NSTimeInterval diff = [timeRightNow timeIntervalSinceDate:date_Picker.date];
// The difference should always be in seconds. Here, 3628800 represents 6 weeks.
if (diff > 3628800){
// Do something if the entered date is six weeks from the iPhone date.
}
}