获取NSDate中具体数字以及获取时间字符串

首先获取你想要知道的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];

你可能感兴趣的:(获取NSDate中具体数字以及获取时间字符串)