Seems like a simple thing but I can't seem to find a way to do it.
It would be great to see a couple different methods.
Overview. NSDate objects encapsulate a single point in time, independent of any particular calendrical system or time zone. Date objects are immutable, representing an invariant time interval relative to an absolute reference date (00:00:00 UTC on 1 January 2001).
Get Today's Date:NSDate* date = [NSDate date];
There are 4 methods for comparing NSDate s in Objective-C: - (BOOL)isEqualToDate:(NSDate *)anotherDate. - (NSDate *)earlierDate:(NSDate *)anotherDate. - (NSDate *)laterDate:(NSDate *)anotherDate.
@Chuck's answer is correct, and lead me to the following code. Thought I'd share:
NSDateComponents *comps = [[NSDateComponents alloc] init]; [comps setDay:10]; [comps setMonth:10]; [comps setYear:2010]; NSDate *date = [[NSCalendar currentCalendar] dateFromComponents:comps];
You can use this
NSString *dateString = @"03-Sep-11"; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; dateFormatter.dateFormat = @"dd-MMM-yy"; NSDate *date = [dateFormatter dateFromString:dateString];
Hope this will help you out.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With