取得NSDate实例各个字段的数字

代码:

 1     NSDate *now = [NSDate date];
 2     NSCalendar *calendar = [NSCalendar currentCalendar];
 3     
 4     //获取年、月、日、时、分、秒等组件
 5     NSDateComponents *dateComponents = [calendar components:NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond fromDate:now];
 6     NSLog(@"[%d]", dateComponents.year);    //
 7     NSLog(@"[%d]", dateComponents.month);   //
 8     NSLog(@"[%d]", dateComponents.day);     //
 9     NSLog(@"[%d]", dateComponents.hour);    //
10     NSLog(@"[%d]", dateComponents.minute);  //
11     NSLog(@"[%d]", dateComponents.second);  //
posted @ 2014-07-20 07:52  ★行云流水★  阅读(127)  评论(0编辑  收藏  举报