开发者

How can I calculate whether an entry is before or after a specific date?

开发者 https://www.devze.com 2023-03-22 22:50 出处:网络
I\'m using Xcode and开发者_运维技巧 I want to compare whether a user-entered date is before or after a specific date.

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
0

精彩评论

暂无评论...
验证码 换一张
取 消