说我有以下内容:
NSDate *today = [NSDate date];
我如何只获得该月的获取整数值?天?还是一年?
答案 0 :(得分:2)
你想要这个NSDateCOmponenets
具体是:
- (NSDateComponents *)components:(NSUInteger)unitFlags fromDate:(NSDate *)date
答案 1 :(得分:-1)
或者你可以使用NSDate类:
NSDate *date = [NSDate date];
int month = [[date descriptionWithCalendarFormat:@"%m" timeZone:nil locale:nil] intValue];
int day = [[date descriptionWithCalendarFormat:@"%d" timeZone:nil locale:nil] intValue];
int year = [[date descriptionWithCalendarFormat:@"%Y" timeZone:nil locale:nil] intValue];
NSLog(@"Today: %i-%i-%i", year, month, day);
希望它有效, ief2