Hello dear I want to retrieve the number of day in the year e.g today is 10th April and I know its 10th day of the month but what if I want the number of the day of the year like today is 99th day of the year.
This is what I have done so far:
NSInteger todaydaysyear;
NSDateFormatter *yearlyDay = [[NSDateFormatter alloc] init];
[yearlyDay setDateFormat:@"dd-yyyy"];
NSDate *currentdateyear = [NSDate date];
NSString *cureentdatestryear = [yearlyDay stringFromDate:currentdateyear];
NSDate *startDateyear = [yearlyDay dateFromString:cureentdatestryear];
NSDateComponents *componentsyear = [[NSCalendar currentCalendar] components:NSCalendarUnitDay | NSCalendarUnitYear fromDate:startDateyear];
todaydaysyear = [componentsyear day];
NSLog(@"here is the day of the year e.g 99th day but not prints month day why%ld", (long)todaydaysyear);
Prints: 10 the current day of the month
What I want: 99th day of the year the current day of the ear count.
Ans: How do you calculate the day of the year for a specific date in Objective-C?