Instance Method


Returns a date representing the absolute time calculated from given components.


- (NSDate *)dateFromComponents:(NSDateComponents *)comps;



The components from which to calculate the returned date.

Return Value

A new NSDate object representing the absolute time calculated from comps. Returns nil if the receiver cannot convert the components given in comps into an NSDate object.


When there are insufficient components provided to completely specify an absolute time, a calendar uses default values of its choice. When there is inconsistent information, a calendar may ignore some of the components parameters or the method may return nil. Unnecessary components are ignored (for example, Day takes precedence over Weekday and Weekday ordinals).

The following example shows how to use this method to create a date object to represent 14:10:00 on 6 January 1965, for a given calendar (gregorian).

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

Note that some computations can take a relatively long time to perform.

See Also

Calculating Dates

- dateByAddingComponents:toDate:options:

Returns a date representing the absolute time calculated by adding given components to a given date.

- dateByAddingUnit:value:toDate:options:

Returns a date representing the absolute time calculated by adding the value of a given component to a given date.

- dateBySettingHour:minute:second:ofDate:options:

Creates a new date calculated with the given time.

- dateBySettingUnit:value:ofDate:options:

Returns a new date representing the date calculated by setting a specific component of a given date to a given value, while trying to keep lower components the same.

- dateWithEra:year:month:day:hour:minute:second:nanosecond:

Returns a date created with the given components.

- dateWithEra:yearForWeekOfYear:weekOfYear:weekday:hour:minute:second:nanosecond:

Returns a new date created with the given components base on a week-of-year value.

- nextWeekendStartDate:interval:options:afterDate:

Returns by reference the starting date and time interval range of the next weekend period after a given date.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software