//获取当前时间,日期
NSDate *currentDate = [NSDatedate];
NSDateFormatter *dateFormatter = [[NSDateFormatteralloc] init];
[dateFormatter setDateFormat:@"YYYY-MM-dd"];
NSString *currentDateString = [dateFormatter stringFromDate:currentDate];
//获取前一个月的时间
NSDate *monthagoData = [selfgetPriousorLaterDateFromDate:currentDatewithMonth:-1];
NSString *agoString = [dateFormatterstringFromDate:monthagoData];
-(NSDate *)getPriousorLaterDateFromDate:(NSDate *)date withMonth:(int)month{
NSDateComponents *comps = [[NSDateComponentsalloc] init];
[comps setMonth:month];
NSCalendar *calender = [[NSCalendaralloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];// NSGregorianCalendar
NSDate *mDate = [calenderdateByAddingComponents:compstoDate:date options:0];
return mDate;
}