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 allocinitWithCalendarIdentifier:NSGregorianCalendar];

    NSDateComponents *comps = nil;

    comps = [calendar components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit fromDate:mydate];

    NSDateComponents *adcomps = [[NSDateComponents allocinit];

    [adcomps setYear:0];

    [adcomps setMonth:-1];

    [adcomps setDay:0];

 

    NSDate *newdate = [calendar dateByAddingComponents:adcomps toDate:mydate options:0];


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM