I have an NSDate that I get from a UIDatepicker.
IBOutlet UIDatePicker *dueDate;
NSDate *selectedDate = [dueDate date];
how do I retrieve the month from dueDate in the form of an int? (1 for Jan, 2 for Feb, etc)
From stackoverflow
-
use
-[NSCalendar components:fromDate:]
for instance the example here: -
NSDateFormatter *dateFormat = [[[NSDateFormatter alloc] initWithDateFormat:@"%m" allowNaturalLanguage:NO] autorelease]; int month = [[dateFormat stringFromDate:dueDate] intValue];
-
NSCalendar *calendar = [NSCalendar currentCalendar]; NSDateComponents *components = [calendar components:NSMonthCalendarUnit fromDate:[dueDate date]]; NSInteger month = [components month];
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.