Declaration.
- (NSDateComponents *)components:(NSUInteger)unitFlags fromDate:(NSDate *)date
Parameters
- unitFlags
- The components into which to decompose date—a bitwise
OR
ofNSCalendarUnit
constants.
[List of NSCalendar Calendar Units]// Following list is quoted from Apple Developer Site.//enum { NSEraCalendarUnit = kCFCalendarUnitEra, NSYearCalendarUnit = kCFCalendarUnitYear, NSMonthCalendarUnit = kCFCalendarUnitMonth, NSDayCalendarUnit = kCFCalendarUnitDay, NSHourCalendarUnit = kCFCalendarUnitHour, NSMinuteCalendarUnit = kCFCalendarUnitMinute, NSSecondCalendarUnit = kCFCalendarUnitSecond, NSWeekCalendarUnit = kCFCalendarUnitWeek, NSWeekdayCalendarUnit = kCFCalendarUnitWeekday, NSWeekdayOrdinalCalendarUnit = kCFCalendarUnitWeekdayOrdinal NSQuarterCalendarUnit = kCFCalendarUnitQuarter, }; typedef NSUInteger NSCalendarUnit;
- date
- The date for which to perform the calculation.
[Example]
// Get current date and translate it into YY/MM/DD format.
// Get current date and translate it into YY/MM/DD format.
//
NSDate *today = [NSDate date];
NSCalendar *calendar = [NSCalendar currentCalendar];
NSDateComponents *todayComp = [calendar components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit) fromDate:today];