-4
这里的情况是如何从NSDate获取当前日期,时间,年份?
我今天作为
+ (NSDateComponents *)getTodayComponents {
NSDate *today = [[NSDate alloc] init];
NSCalendar *calendar = [NSCalendar currentCalendar];
return [calendar components:NSCalendarUnitYear | NSCalendarUnitMonth fromDate:today];
}
的方法,通过它我可以得到日,月,年,小时,分钟,等了现在
我需要改变的日,月和年从另一NSDate
来了,所以我的代码看起来像
- (void)datePickerView:(RSDFDatePickerView *)view didSelectDate:(NSDate *)date {
NSDate *today = [[NSDate alloc] init];
NSDateComponents *todayComponents = [Helper getTodayComponents];
self.transactionDate = date;
NSLog(@"%@", [date description]);
self.inputDateField.text = [[Helper getDateFormatterForClient] stringFromDate:self.transactionDate];
[self.inputDateField resignFirstResponder];
}
问题
如何,我可以得到一年,一天,一个月today
,这样我可以在todayComponents设置?
查看'NSDateComponents'的文档。各个组件都有明显的属性。 – rmaddy
你是指选择器上选择的日期吗? - 即参数“日期”?只需将它传递给你的帮助函数,并用它来代替新的日期对象。 – Paulw11