一来一回,

4.4、通过NSCALENDAR类来创建日期 

        NSDateComponents *comp = [[NSDateComponents alloc]init]; 

        [comp setMonth:06]; 

        [comp setDay:01]; 

        [comp setYear:2001]; 

        NSCalendar *myCal = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; 

        NSDate *myDate1 = [myCal dateFromComponents:comp]; 

        NSLog(@"myDate1 = %@",myDate1); 

 

4.5、从已有日期获取日期 

        unsigned units  = NSMonthCalendarUnit|NSDayCalendarUnit|NSYearCalendarUnit; 

        NSDateComponents *comp1 = [myCal components:units fromDate:now]; 

        NSInteger month = [comp1 month]; 

        NSInteger year = [comp1 year]; 

        NSInteger day = [comp1 day]; 

原文地址:https://www.cnblogs.com/guligei/p/3196018.html