Instance Method


Returns the specified date component from a given date.


func component(_ unit: NSCalendar.Unit, from date: Date) -> Int



The component to return. For possible values, see NSCalendar.Unit.


The date for which to perform the calculation.

Return Value

An NSInteger value for the requested component.

See Also

Extracting Components

func date(Date, matchesComponents: DateComponents) -> Bool

Returns whether a given date matches all of the given date components.

func components(NSCalendar.Unit, from: Date) -> DateComponents

Returns the date components representing a given date.

func components(NSCalendar.Unit, from: Date, to: Date, options: NSCalendar.Options) -> DateComponents

Returns the difference between two supplied dates as date components.

func components(in: TimeZone, from: Date) -> DateComponents

Returns all the date components of a date, as if in a given time zone (instead of the receiving calendar’s time zone).

Beta Software


Learn more about using Apple's beta software