This was copied directly from a blog post of Murat Yilmaz
1 2 3 4 5 6 7 8 9 10 11
| NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier: NSGregorianCalendar]; NSCalendarUnit unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSWeekCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit; NSDate *date = [NSDate date]; NSDateComponents *dateComponents = [calendar components:unitFlags fromDate:date]; NSInteger year = [dateComponents year]; NSInteger month = [dateComponents month]; NSInteger week = [dateComponents week]; NSInteger day = [dateComponents day]; NSInteger hour = [dateComponents hour]; NSInteger minute = [dateComponents minute]; NSInteger second = [dateComponents second];
|