이 시도 :
let calender = NSCalendar.currentCalendar()
let dateComponent = calender.components(NSCalendarUnit.WeekOfYearCalendarUnit | NSCalendarUnit.DayCalendarUnit | NSCalendarUnit.MonthCalendarUnit | NSCalendarUnit.YearCalendarUnit, fromDate:NSDate())
println ("Week: = \(dateComponent.weekOfYear)")
따라서 응답은 다음과 같이해야한다
NSDateComponents *components = [[NSCalendar currentCalendar] components:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear | NSCalendarUnitWeekOfMonth fromDate:[NSDate date]];
NSInteger curr_month = [components month];
NSInteger curr_year = [components year];
NSInteger curr_date = [components day];
NSLog(@"%d %d %d, \n Week no: %ld",curr_date, curr_month,curr_year, (long)[components weekOfMonth]);
출력 것은 : 2015년 1월 22일 (18) : 19 : 40.209 샘플 [38734 : 3031191] 22 1 2015,
주 번호 : 4
재생산 할 수 없습니다. 'let myDate = NSDate()'를 사용하면 코드가 올바른 값인'4'를 반환합니다. –
입력 데이터가있는 자그마한 예제 (실제)와 예상 된 출력이 도움이 될 것입니다. –
노력에 감사드립니다, 마틴. 어떻게 든 입력 날짜를 엉망으로 만들었습니다. – TommyF