- (IBAction)reslut_value:(id)sender
{
/*分别表示年、月、日、时、分、秒*/
NSInteger unitFlags = NSYearCalendarUnit |
NSMonthCalendarUnit |
NSDayCalendarUnit |
NSWeekCalendarUnit |
NSHourCalendarUnit|
NSMinuteCalendarUnit |
NSSecondCalendarUnit;
//********************
NSDate *date = [NSDate date];
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *comps;
comps = [calendar components: unitFlags fromDate:date];
/*分别取出年、月、日、时、分、秒*/
int year = [comps year];
int month = [comps month];
int day = [comps day];
int hour = [comps hour];
int min = [comps minute];
int sec = [comps second];
//************************
/*打印输出time*/
NSLog(@"time:%i-%i-%i %i:%i:%i\n",year,month,day,hour,min,sec);
}
//输出结果为: Calculator[2233:f803] time:2012-6-27 16:13:23