Knowing the month and day of a certain year, what is the week of that year?


NSDateComponents *compt = [[NSDateComponents allocinit];

    [compt setYear:2015];

    [compt setMonth:12];

    [compt setDay:15];

    NSCalendar *calendar = [NSCalendar currentCalendar];

    NSDate *date = [calendar dateFromComponents:compt];

    NSUInteger count = [calendar ordinalityOfUnit:NSCalendarUnitWeekOfYear inUnit:NSCalendarUnitYear forDate:date];


The value of count is 51, which is the 51st week of 2015;

For detailed explanation, please see the blog: http://blog.csdn.net/felicity294250051/article/details/48496859


Guess you like

Origin blog.csdn.net/qq_27740983/article/details/50327183