iphone - 使用NSDateComponents的月份的最后一个工作日

标签 iphone ios cocoa-touch nsdate nsdatecomponents

NSDateComponentsNSCalendar具有使用NSWeekdayOrdinalCalendarUnitNSCalendarUnit一起获取月份的第n个工作日的功能。

例如,每月的第二个星期一。

很棒,但是,我需要检查NSDate的某个实例是该月的最后一个工作日还是第二个工作日。 我想不出一种整齐的方法来做到这一点。我希望有一个简单的技巧,它不需要您遍历整个月的所有星期一。

你们有什么主意吗?

最佳答案

只需添加7天(使用NSCalendardateByAddingComponents:toDate:options:),然后检查结果月份是否相同即可。

关于iphone - 使用NSDateComponents的月份的最后一个工作日,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16033103/

相关文章:

iphone - 获取 UITextView 键盘的 y 值

ios - 如何检测iPhone相机是否未拍摄图像?

ios - Xcode 8 Objective-C 类别警告

swift - RxSwift Driver 值的变异

ios - 更改单独字符串的字体detailTextLabel

iphone - 性能问题 - iOS 中的 plist 与 sqlite

iphone - 如何使用 iPhone 将照片上传到服务器?

ios - UIScrollView scrollRectToVisible :animated: is there a way that a method can be called when animation ends

ios - 自动更新消息

iphone - 从以编程方式创建的 tableViewCell 中删除图像