获取3个月前的时间(获取某一天的时间 NSDate)

p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo }
p.p2 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; min-height: 21.0px }
p.p3 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #3d1d81 }
p.p4 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #1d9421 }
p.p5 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #6122ae }
span.s1 { }
span.s2 { color: #c32275 }
span.s3 { color: #6122ae }
span.s4 { color: #3d1d81 }
span.s5 { color: #c91b13 }
span.s6 { color: #000000 }
span.s7 { color: #703daa }
span.s8 { color: #0435ff }

-(void)getThreeMonthDate:(NSDate *)mydate

{

NSLog(@"%@",mydate);

//1.创建NSCalendar

NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];

//2.改变NSDateComponents

NSDateComponents *adcomps = [[NSDateComponents alloc] init];

[adcomps setYear:0];

[adcomps setMonth:-3];

[adcomps setDay:0];

//3.获取NSDate

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

NSLog(@"%@",newdate);

}

上一篇:Linux 脚本编写基础


下一篇:Linux 生产实习01