这一定很简单,但我无法弄明白。
我想在iPhone中找到周数作为整数。
这显示了如何获取String Code
-(NSString*) getWeekOfMonth {
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];
[dateFormatter setTimeStyle:NSDateFormatterShortStyle];
[dateFormatter setDateFormat:@"W"];
NSString *weekNumber = [dateFormatter stringFromDate:[NSDate date]];
[dateFormatter release];
return weekNumber;
}
由于
答案 0 :(得分:1)
使用integerValue
:
NSInteger weekInt = [weekNumber integerValue];
答案 1 :(得分:0)
int intWeekNumber = [weekNumber intValue];
答案 2 :(得分:0)
或使用:
CFAbsoluteTime currentTime = CFAbsoluteTimeGetCurrent();
CFTimeZoneRef currentTimeZone = CFTimeZoneCopyDefault();
SInt32 weekNumber = CFAbsoluteTimeGetWeekOfYear(currentTime, currentTimeZone);