Instance Method

component(_:from:)

Returns the specified date component from a given date.

Declaration

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

Parameters

unit

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

date

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)

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

func components(NSCalendar.Unit, from: Date)

Returns the date components representing a given date.

func components(NSCalendar.Unit, from: Date, to: Date, options: NSCalendar.Options = [])

Returns the difference between two supplied dates as date components.

func components(NSCalendar.Unit, from: DateComponents, to: DateComponents, options: NSCalendar.Options = [])

Returns the difference between start and end dates given as date components.

func components(in: TimeZone, from: Date)

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