我该如何计算日历周?一年有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);
取自http://iosdevelopertips.com/cocoa/date-formatter-examples.html
我在哪里可以找到允许的日期格式?
解决方法
使用NSCalendar和NSDateComponents.
NSCalendar *cal = [NSCalendar currentCalendar]; NSDateComponents *components = [cal components:NSWeekCalendarUnit fromDate:date]; NSInteger week = [components week];