[NSDate dateWithTimeIntervalSinceNow:(3600*24*7*(weeks))]
我知道自事件重复以来已经过去了几个月,但是我未能确定如何制作一个NSDate对象,这个对象将来代表1个月/ 3个月/ 6个月/ 9个月。理想情况下,我希望用户从10月14日起每月重复一次,每月14号重复一次。
解决方法 (几乎和 this question相同)从documentation:
Use of NSCalendarDate strongly
discouraged. It is not deprecated yet,
however it may be in the next major OS
release after Mac OS X v10.5. For
calendrical calculations,you should
use suitable combinations of
NSCalendar,NSDate,and
NSDateComponents,as described in
Calendars in 07002.
接下来的建议:
NSDate *today = [NSDate date];NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIDentifIEr:NSGregorianCalendar];NSDateComponents *components = [[NSDateComponents alloc] init];components.month = 1;NSDate *nextMonth = [gregorian dateByAddingComponents:components toDate:today options:0];[components release];NSDateComponents *nextMonthComponents = [gregorian components:NSYearCalendarUnit | NSMonthCalendarUnit fromDate:nextMonth];NSDateComponents *todayDayComponents = [gregorian components:NSDayCalendarUnit fromDate:today];nextMonthComponents.day = todayDayComponents.day;NSDate *nextMonthDay = [gregorian dateFromComponents:nextMonthComponents];[gregorian release];
可能有更直接或更有效的实施,但这应该是准确的,应该指向正确的方向。
总结以上是内存溢出为你收集整理的objective-c – 修改NSDate从今天起1个月全部内容,希望文章能够帮你解决objective-c – 修改NSDate从今天起1个月所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)