这是设置:
NSDateComponents* temporalComponents;
temporalComponents = [theDateComponents copy]; //another component set to todays date.
[temporalComponents setDay: [temporalComponents day] + (offset * 7)]
如果我输出组件的结果,则表明正确添加了天数,例如 21 天。
"<NSDateComponents: 0x6a48820>\n Calendar Year: 2012\n Month: 2\n Day: 49\n Hour: 13\n Minute: 12"
但当然我希望它有这个更正的“包装”组件列表,其中月份增加并且日期被更正..(主要是因为我做了进一步的操作,我可以替换整个组件,而不仅仅是添加到组件)换句话说,我的最终产品是 NSDateComponent,因此可以进一步对其进行操作。
"<NSDateComponents: 0x6a48820>\n Calendar Year: 2012\n Month: 3\n Day: 20\n Hour: 13\n Minute: 12"
现在我这样做是为了正确地包裹日子(以及其他需要包裹的东西)
NSDate* tempDate = [CURRENTC dateFromComponents:temporalComponents];
temporalComponents2 = [CURRENTC components:unitFlags fromDate:tempDate];
[theDatesArray addObject: temporalComponents2];
有没有更好的方法?无需去约会,然后回到组件。我一直在寻找更好的方法但没有成功,也许我在搜索错误的术语。