从NSDate中分别分离提取出年月日分时秒的方法
NSDate *now = [NSDate date]; NSCalendar *cal = [NSCalendar currentCalendar]; unsigned int unitFlags = NSWeekdayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit; NSDateComponents *dd = [cal components:unitFlags fromDate:now]; int week = [dd weekday]; int hour = [dd hour]; int minute = [dd minute]; second = [dd second];
That is it!