UIDatePicker和NSDate [英] UIDatePicker and NSDate
本文介绍了UIDatePicker和NSDate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个来自UIDatepicker的NSDate。
I have an NSDate that I get from a UIDatepicker.
IBOutlet UIDatePicker *dueDate;
NSDate *selectedDate = [dueDate date];
如何从 dueDate
中检索月份以 int
的形式? (1月1日,2月2日等)
How do I retrieve the month from dueDate
in the form of an int
? (1 for Jan, 2 for Feb, etc.)
推荐答案
NSCalendar *calendar = [NSCalendar currentCalendar];
NSDateComponents *components = [calendar components:NSMonthCalendarUnit fromDate:[dueDate date]];
NSInteger month = [components month];
这篇关于UIDatePicker和NSDate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文