ioscocoa-touchnsdatensdateformatternscalendar

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


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.


Solution

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