计算日历周

tes*_*ing 3 iphone xcode calendar objective-c

我该如何计算日历周?一年有52/53周,有两个规则:

-美国

-DIN 1355/ISO 8601

我想使用DIN 1355/ISO 8601.我该如何管理?

编辑:

NSDate *today = [NSDate date];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"ww"];
NSString *weeknumber = [dateFormat stringFromDate: today];
NSLog(@"week: %@", weeknumber);
Run Code Online (Sandbox Code Playgroud)

取自http://iosdevelopertips.com/cocoa/date-formatter-examples.html

我在哪里可以找到允许的日期格式?

Elf*_*red 5

使用NSCalendarNSDateComponents.

NSCalendar *cal = [NSCalendar currentCalendar];
NSDateComponents *components = [cal components:NSWeekCalendarUnit fromDate:date];
NSInteger week = [components week];
Run Code Online (Sandbox Code Playgroud)