We can get day, month and year components of NSDate in integer form. For example, if the date is 1/2/2014 then we should get 1, 2 and 2014 separately as an integer.
We can achieve this with the help of the NSDateComponents. NSDateComponents helps you to get day, month and year in integer format from NSDate. The objective-c code snippet for this is given below:
for more details on NSDateComponents
We can achieve this with the help of the NSDateComponents. NSDateComponents helps you to get day, month and year in integer format from NSDate. The objective-c code snippet for this is given below:
NSDate *currentDate = [NSDate date];
NSCalendar* calendar = [NSCalendar currentCalendar];
NSDateComponents* components = [calendar components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit fromDate:currentDate]; // Get necessary date components
[components month]; //gives you month
[components day]; //gives you day
[components year]; // gives you year
for more details on NSDateComponents