iOS-获取当前时间的年、月、日、时、分、秒

 //获取当前时间  
   NSDate *now = [NSDate date];   
   NSLog(@”now date is: %@”, now);
   NSCalendar *calendar = [NSCalendar currentCalendar];  
  NSUInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;  
   NSDateComponents *dateComponent = [calendar components:unitFlags fromDate:now];   
   int year = [dateComponent year];
   int month = [dateComponent month]; 
   int day = [dateComponent day];  
   int hour = [dateComponent hour];  
   int minute = [dateComponent minute];
   int second = [dateComponent second]; 
     NSLog(@”year is: %d”, year);17   
     NSLog(@”month is: %d”, month);18 
     NSLog(@”day is: %d”, day);19   
     NSLog(@”hour is: %d”, hour);20  
     NSLog(@”minute is: %d”, minute);21  
      NSLog(@”second is: %d”, second);
相关文章
相关标签/搜索