iOS: How to get NSDate day, month and year in integer format?

If you want to get day, month and year components of NSDate in integer use this:

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
You can use NSDateComponents for that as above.
Please visit this page for details.
Hope it helps.
iOS: How to get NSDate day, month and year in integer format? iOS: How to get NSDate day, month and year in integer format? Reviewed by Ricardo Castellanos on 9:39 Rating: 5

No hay comentarios:

Con la tecnología de Blogger.