获取当前时间警告eprecated in iOS 9.0 - Use [NSURLSession dataTaskWithRequest:completionHandler:] (see NSURLS

  

//警告

NSUInteger unitFlags = kCFCalendarUnitYear | kCFCalendarUnitMonth | kCFCalendarUnitDay | kCFCalendarUnitHour |  kCFCalendarUnitMinute | kCFCalendarUnitSecond; 


//替换

  NSUInteger unitFlags = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;


    NSCalendar *calendar = [NSCalendar currentCalendar];

    NSUInteger unitFlags = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;

//        NSUInteger unitFlags = kCFCalendarUnitYear | kCFCalendarUnitMonth | kCFCalendarUnitDay | kCFCalendarUnitHour |  kCFCalendarUnitMinute | kCFCalendarUnitSecond;

    NSDateComponents *dateComponent = [calendar components:unitFlags fromDate:now];

    

    

    NSInteger year = [dateComponent year];

    NSInteger month =  [dateComponent month];

    NSInteger day = [dateComponent day];

    NSInteger hour =  [dateComponent hour];

    NSInteger minute =  [dateComponent minute];

   // NSInteger second = [dateComponent second];


//    

//    NSLog(@"year is: %ld", (long)year);

//    NSLog(@"month is: %ld", (long)month);

//    NSLog(@"day is: %ld", (long)day);

//    NSLog(@" hour is: %ld",  (long)hour);

//    NSLog(@"minute  is: %ld", (long)minute );

//    NSLog(@"second is: %ld", (long)second);




 

你可能感兴趣的:(iOS开发)