ios 获取n个月前或者n个月后的日期
NSCalendar *calendar = [NSCalendar currentCalendar];
NSRange range =
[calendar rangeOfUnit:NSDayCalendarUnit inUnit:NSMonthCalendarUnit
forDate:[NSDate date]];
NSUInteger numberOfDaysInMonth =
range.length;
NSDate *datetime = [NSDate
dateWithTimeIntervalSince1970:csmcurrentTime-(86400*numberOfDaysInMonth *
data_current_index)];
NSDateFormatter *dateformat = [[[NSDateFormatter
alloc] init] autorelease];
[dateformat setDateFormat:@"yyyy年MM月"];
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *comps = nil;
comps = [calendar components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit fromDate:mydate];
NSDateComponents *adcomps = [[NSDateComponents alloc] init];
[adcomps setYear:0];
[adcomps setMonth:-1];
[adcomps setDay:0];
NSDate *newdate = [calendar dateByAddingComponents:adcomps toDate:mydate options:0];
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。