标签:
-(void)timeStr
{
NSDate *date = [NSDate date];
NSInteger unitFlags = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;
NSCalendar *currentCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
formatter.dateFormat = @"yyyy.MM";
NSDateComponents *currentComps = [currentCalendar components:unitFlags fromDate:date];
NSDateComponents *resultComps = [[NSDateComponents alloc]init];
[resultComps setYear:[currentComps year]];
[resultComps setMonth:[currentComps month]];
[resultComps setWeekday:[currentComps weekday]];
NSInteger mMonth = [currentComps month];
for(int i =3;i>-1;i--){
NSInteger uMonth = mMonth - i;
[resultComps setMonth:uMonth];
NSDate *returnDate = [currentCalendar dateFromComponents:resultComps];
NSString *returnStr = [formatter stringFromDate:returnDate];
NSLog(@"%@",returnStr);
}
}
2月份的 30日 = 3月份,我日错了
标签:
原文地址:http://www.cnblogs.com/guligei/p/5336571.html