I have two dates: 2009-05-11
and the current date. I want to check whether the given date is the current date or not. How is this possible.
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- back button text does not change
- iOS (objective-c) compression_decode_buffer() retu
- how to find the index position of the ARRAY Where
相关文章
- 现在使用swift开发ios应用好还是swift?
- TCC __TCCAccessRequest_block_invoke
- xcode 4 garbage collection removed?
- Unable to process app at this time due to a genera
- How can I add media attachments to my push notific
- didBeginContact:(SKPhysicsContact *)contact not in
- MYSQL: How can I find 'last monday's date&
- Custom Marker performance iOS, crash with result “
Here's the function from Naveed Rafi's answer converted to Swift if anyone else is looking for it:
This category offers a neat way to compare NSDates:
And the implementation:
Simple to use:
There are other ways that you may use to compare an NSDate objects. Each of the methods will be more efficient at certain tasks. I have chosen the compare method because it will handle most of your basic date comparison needs.
Here's the Swift variant on Pascal's answer:
Which can be used as:
What you really need is to compare two objects of the same kind.
Create an NSDate out of your string date (@"2009-05-11") :
http://blog.evandavey.com/2008/12/how-to-convert-a-string-to-nsdate.html
If the current date is a string too, make it an NSDate. If its already an NSDate, leave it.
If you make both dates
NSDate
s you can useNSDate
'scompare:
method:You can take a look at the docs here.