我想从周数和年份获取日期。我从服务器获得周数和年份。我正在尝试以下代码,但它不会工作。
NSDateFormatter *dateFormatter2 = [[NSDateFormatter alloc] init];
// this is imporant - we set our input date format to match our input string
// if format doesn't match you'll get nil from your string, so be careful
[dateFormatter2 setDateFormat:@"yyyy-MM-dd"];
NSDate *now = [dateFormatter2 dateFromString:@"2001-01-01"];
NSCalendar *gregorian1 = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *comps1 = [gregorian1 components:NSWeekdayCalendarUnit | NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit fromDate:now];
[comps1 setYear:2013];
[comps1 setWeek:51];
[comps1 setWeekday:2];
NSDate *resultDate = [gregorian1 dateFromComponents:comps1];
输出为:- 2012-12-31 18:30:00 +0000
我究竟做错了什么 ?提前致谢..