UIDatePicker and NSDate

I have an NSDate that I get from UIDatepicker.

IBOutlet UIDatePicker *dueDate;
NSDate *selectedDate = [dueDate date];

How to get a month out dueDateof shape int? (1 for January, February 2, etc.)

+3
source share
3 answers
NSCalendar *calendar = [NSCalendar currentCalendar];
NSDateComponents *components = [calendar components:NSMonthCalendarUnit fromDate:[dueDate date]];
NSInteger month = [components month];
+9
source
+5
source
NSDateFormatter *dateFormat = [[[NSDateFormatter alloc] initWithDateFormat:@"%m" allowNaturalLanguage:NO] autorelease];
int month = [[dateFormat stringFromDate:dueDate] intValue];
+1
source

Source: https://habr.com/ru/post/1706079/


All Articles