1

NSDateComponents and NSCalendar have a feature to get the n'th weekday of the month with the NSWeekdayOrdinalCalendarUnit using NSCalendarUnit.

For example the 2nd monday of the month.

It's awesome but, I need to check if a certain instance of NSDate is the last or second last weekday of the month. I can't think of a neat way to do this. I hope there is a simple trick that does not require you to loop through all the mondays of the whole month.

Do you guys have any ideas?

4

1 回答 1

3

只需添加 7 天(使用NSCalendar's dateByAddingComponents:toDate:options:)并检查生成的月份是否相同。

于 2013-04-16T09:20:17.463 回答