首先获取你想要知道的Date——aDate;
NSDate *aDate;
NSCalendar *calendar=[NSCalendar currentCalendar];
NSDateComponents *components=[calendar components:NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay fromDate:aDate];
NSInteger year=[components Year];
NSInteger month=[components Month];
NSInteger day=[components day];
注意:只能获取你声明的NSCalendarUnit的数据
NSDateFormatter *dateFormater=[[NSDateFormatter alloc]init];
[dateFormater setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSString *feedBackDate=[dateFormater stringFromDate:aNSDate];
网友评论