Determine if today's date is in a range of two dates on iOS [duplicate]

时光毁灭记忆、已成空白 提交于 2019-12-17 18:42:10

问题


Possible Duplicate:
How to compare two dates in Objective-C

I'd like to pop up a message in one of my apps when the date is in the range of two dates (e.g. the holiday period)

So like

if(dateInRangeof:date1, date2){True}else{false}

Looking for any code snippets or apis to look at. Cheers


回答1:


- (BOOL)isDate:(NSDate *)date inRangeFirstDate:(NSDate *)firstDate lastDate:(NSDate *)lastDate {
   return [date compare:firstDate] == NSOrderedDescending &&
          [date compare:lastDate]  == NSOrderedAscending;
}



回答2:


How to compare two dates in Objective-C

This should be what you're looking for.

If you look in the documentation for NSDate you should find a lot of interesting things.



来源:https://stackoverflow.com/questions/8276187/determine-if-todays-date-is-in-a-range-of-two-dates-on-ios

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!