UIDatePicker and NSDate

前端 未结 3 1656
抹茶落季
抹茶落季 2021-01-14 14:06

I have an NSDate that I get from a UIDatepicker.

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

How do I retrieve t

相关标签:
3条回答
  • 2021-01-14 14:18

    use -[NSCalendar components:fromDate:] for instance the example here:

    http://developer.apple.com/iphone/library/documentation/Cocoa/Reference/Foundation/Classes/NSCalendar_Class/Reference/NSCalendar.html

    0 讨论(0)
  • 2021-01-14 14:27
    NSDateFormatter *dateFormat = [[[NSDateFormatter alloc] initWithDateFormat:@"%m" allowNaturalLanguage:NO] autorelease];
    int month = [[dateFormat stringFromDate:dueDate] intValue];
    
    0 讨论(0)
  • 2021-01-14 14:36
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSDateComponents *components = [calendar components:NSMonthCalendarUnit fromDate:[dueDate date]];
    NSInteger month = [components month];
    
    0 讨论(0)
提交回复
热议问题