我想添加天的日期,我得到了很多代码这一点,但他们都不工作了我下面显示的是我的代码,请别人帮我解决这个问题添加天的NSDate
int daysToAdd=[[appDlegateObj.selectedSkuData
objectForKey:@"Release Time"] intValue];
NSTimeInterval secondsForFollowOn=daysToAdd*24*60*60;
NSString *dateStr=[contentDic objectForKey:@"Date"];
NSDateFormatter *dateFormatter=[[NSDateFormatter alloc]init];
[dateFormatter setDateFormat:@"yyyy-MM-dd"];
NSDate *dateFromString=[[NSDate alloc]init];
dateFromString=[dateFormatter dateFromString:dateStr];
[dateFormatter release];
NSDate *date=[dateFromString dateByAddingTimeInterval:secondsForFollowOn];
谢谢月光,你的代码工作正常。 – karthick
@moonlight:关于dateByRemovingComponents呢?如果我需要在目前的日期前1个月取得新的日期,我该怎么办? –
@BishalGhimire setMonth为-1(用于'dateComponents')或任何你想要减去的数字。 –