首先獲取你想要知道的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的數(shù)據(jù)
NSDateFormatter *dateFormater=[[NSDateFormatter alloc]init];
[dateFormater setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSString *feedBackDate=[dateFormater stringFromDate:aNSDate];