如何在目标 C 中未设置年份的情况下检查日期是否在范围内
有没有办法检查 NSDate 对象是否在月日范围内,而没有在范围内设置年份。例如,我的 NSDate 等于 1956 年 2 月 2 日,我想查明该日期是否在任何年份的 1 月 10 日到 2 月 10 日之间。
先感谢您!
Is there a way to check if NSDate object is in the range of month day with out having a year set in range. For example I have NSDate eqaual to February 2 1956 and I want find out if that date is in range between January 10 and February 10 within any year.
Thank you in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用 NSCalendar 和 NSDateComponents。
例如
Use
NSCalendar
andNSDateComponents
.e.g.
您应该使用 NSDate 的
-compare
消息,或者使用-timeIntervalSince1970
You should use NSDate's
-compare
message, or, use-timeIntervalSince1970
您可以获取当前的 NSCalendar 实例并使用 Components:forDate: 方法,然后从结果 NSDateComponents 对象。
You can get the current NSCalendar instance and use the components:forDate: method, then extract the month and date components from the resulting NSDateComponents object.
您可以为此使用 NSDateComponents
You can use NSDateComponents for this