Modifying NSDate to represent 1 month from today

后端 未结 5 466
夕颜
夕颜 2021-01-31 11:07

I\'m adding repeating events to a Cocoa app I\'m working on. I have repeat every day and week fine because I can define these mathematically (3600*24*7 = 1 week). I use the foll

5条回答
  •  不知归路
    2021-01-31 11:53

    I'll probably use NSCalendarDate.

    Get current date's dayOfMonth, monthOfYear and yearOfCommonEra, as three numbers.

    Add the required number of months (1/3/6/9), taking care of 1) whether that date exist (e.g. 31 April, 29 Feb on a non-leap year), and 2) roll-over of year.

    Create that new date with NSCalendarDate's initWithYear:month:day:hour:minute:second:timeZone:

提交回复
热议问题