I'm using Xcode and开发者_运维技巧 I want to compare whether a user-entered date is before or after a specific date.
For example, the user enters "February 12, 1992" into their phone. I need to determine if that is before or after June 10, 1994. Then I will take specific action based on this result.
NSDate has two methods earlierDate: and laterDate: You can also use compare: method to compare dates.
- Make an NSDate for June 10, 1994
- Make an NSDateFormatter to parse the user input.
- dateFromString: of the date formatter will give you an NSDate
- compare the dates as suggested in the answer by EmptyStack
精彩评论