Monday, May 23, 2011

NSCalendar dateFromComponents example objc

NSCalendar dateFromComponents performs just the reverse of NSCalendar components:fromDate: method. It returns a NSDate object created from the information of NSDateComponents object. [NSCalendar dateFromComponents example]

Declaration.

- (NSDate *)dateFromComponents:(NSDateComponents *)comps
Parameters
comps
The components from which to calculate the returned date.

Example.

NSDateComponents *comps = [[NSDateComponents alloc] init];
[comps setYear:1965];
[comps setMonth:1];
[comps setDay:6];
[comps setHour:14];
[comps setMinute:10];
[comps setSecond:0];
NSDate *date = [gregorian dateFromComponents:comps];
[comps release];