timestr
Posted 高山流水
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了timestr相关的知识,希望对你有一定的参考价值。
-(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月份,我日错了
以上是关于timestr的主要内容,如果未能解决你的问题,请参考以下文章