Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- NSCalendar *currentCalendar = [NSCalendar currentCalendar];
- NSDate *today = [NSDate date];
- NSInteger dc = [currentCalendar ordinalityOfUnit:NSDayCalendarUnit
- inUnit:NSYearCalendarUnit
- forDate:today];
- //create calendar
- NSCalendar *calendar = [NSCalendar currentCalendar];
- //set calendar time zone
- [calendar setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]];
- //gather date components
- NSDateComponents *components = [calendar components:NSDayCalendarUnit fromDate:[NSDate date]];
- //gather time components
- NSInteger day = [components day];
- NSCalendar *cal = [NSCalendar currentCalendar];
- NSDateFormatter *df = [[NSDateFormatter alloc] init];
- [df setCalendar:cal];
- [df setDateFormat:@"DDD"]; // D specifier used for day of year
- NSString *dayOfYearString = [df stringFromDate:someDate]; // you choose 'someDate'
- NSLog(@"The day is: %@", dayOfYearString);
- // create your NSDate and NSCalendar objects
- NSDate *today = [NSDate date];
- NSDate *referenceDate;
- NSCalendar *calendar = [NSCalendar currentCalendar];
- // get today's date components
- NSDateComponents *components = [calendar components:NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit fromDate:today];
- // changing the date components to the 31nd of December of last year
- components.day = 31;
- components.month = 12;
- components.year--;
- // store these components in your date object
- referenceDate = [calendar dateFromComponents:components];
- // get the number of days from that date until today
- components = [calendar components:NSDayCalendarUnit fromDate:referenceDate toDate:[NSDate date] options:0];
- NSInteger days = components.day;
Add Comment
Please, Sign In to add comment