Anzahl der Wochen im Monat
Ich habe folgenden Code:
NSDate *dateNow = [[NSDate alloc] init];
NSTimeInterval timeDifference = [usersDate timeIntervalSinceDate:dateNow];
// Get the system calendar
NSCalendar *sysCalendar = [NSCalendar currentCalendar];
// Create the NSDates
NSDate *date1 = [[NSDate alloc] init];
NSDate *date2 = [[NSDate alloc] initWithTimeInterval:timeDifference sinceDate:date1];
// Get conversion to months, days, hours, minutes
unsigned int unitFlags = NSWeekCalendarUnit | NSYearCalendarUnit | NSMonthCalendarUnit | NSSecondCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSDayCalendarUnit | NSMonthCalendarUnit;
NSDateComponents *breakdownInfo = [sysCalendar components:unitFlags fromDate:date1 toDate:date2 options:0];
NSLog(@"Break down: %d Years, %d months, %d Weeks, %d days %d Hours, %d Minutes, %d Seconds", [breakdownInfo year], [breakdownInfo month], [breakdownInfo week], [breakdownInfo day], [breakdownInfo hour], [breakdownInfo minute], [breakdownInfo second]);
Es druckt Ausgaben wie:
Break down: 0 Years, 5 months, 3 Weeks, 4 days 2 Hours, 48 Minutes, 20 Seconds
Ich brauche eigentlich nicht die Anzahl der Monate bis zum Datum, sondern die Gesamtzahl der Wochen. Kann ich den Code dafür trotzdem ändern? Ich möchte nicht einfach davon ausgehen, dass 1 Monat = 4 Wochen, da dies zweifellos falsch wäre.
Mit freundlichen Grüßen