首页 > 代码库 > 年,月,日,时,分,秒

年,月,日,时,分,秒

NSDate *now = [NSDate date];
NSCalendar *cal = [NSCalendar currentCalendar];
unsigned int unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit | NSWeekdayCalendarUnit;
NSDateComponents *dd = [cal components:unitFlags fromDate:now]; 
int y = [dd year];
int m = [dd month];
int d = [dd day];
int week = [dd weekday];
int hour = [dd hour];
int minute = [dd minute];
int second = [dd second];


年,月,日,时,分,秒