I want to get the Week number of the year from the date.I tried the code as follow but gives me a wrong week number.
My code for week number:
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"YYYY-MM-dd"];
NSDate *date = [dateFormatter dateFromString:@"2012-09-15"];
NSCalendar *calendar = [NSCalendar currentCalendar];
NSLog(@"week: %i", [[calendar components: NSWeekOfYearCalendarUnit fromDate:date] weekOfYear]); //Display 38 instead of 37
}
Note: If i try with with [NSDate date]
display the correct.
Help me to solve this.. Thank you,
See Question&Answers more detail:os