ObjectiveC:
NSCalendar *calendar = [NSCalendar currentCalendar];
NSDateComponents *dateComponent = [calendar components:(NSWeekOfYearCalendarUnit | NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit) fromDate:[NSDate date]];
NSLog(@"%@",dateComponent);
Update
NSCalendar *calendar = [NSCalendar currentCalendar];
NSDateComponents *dateComponent = [calendar components:(NSCalendarUnitWeekOfYear | NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear) fromDate:date];
NSLog(@"%@",dateComponent);
Swift:
let calendar = NSCalendar.currentCalendar()
let dateComponent = calendar.components([.WeekOfYear, .Day, .Month, .Year], fromDate: NSDate(timeIntervalSinceNow: 0))
print("weekOfYear (dateComponent.weekOfYear)")
Swift 3 - Swift 5:
let component = Calendar.current.component(.weekOfYear, from: Date())
print("Week of Year (component)")
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…