ylliX - Online Advertising Network

Quick tip: How to get year, month and day from NSDate

First you have to get NSDateComponents object with year, month and day units:

NSDateComponents *components = [[NSCalendar currentCalendar] components:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear fromDate:[NSDate date]];

then extracting each value is simple:

NSInteger day = [components day];
NSInteger month = [components month];
NSInteger year = [components year];

Leave a Reply