iPhone OS: How do I create an NSDate for a specific date?

nickthedude picture nickthedude · Apr 5, 2010 · Viewed 58.6k times · Source

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.

Answer

Oded Ben Dov picture Oded Ben Dov · Feb 22, 2011

@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];