Instance Method

string(from:)

Returns a formatted string based on the specified date component information.

Declaration

func string(from components: DateComponents) -> String?

Parameters

components

A date components object containing the date and time information to format. The allowedUnits property determines which date components are actually used to generate the string. All other date components are ignored. This parameter must not be nil.

Return Value

A formatted string representing the specified date information.

Discussion

Use this method to format date information that is already broken down into the component day and time values.

See Also

Formatting Values

func string(for: Any?) -> String?

Returns a formatted string based on the date information in the specified object.

func string(from: Date, to: Date) -> String?

Returns a formatted string based on the time difference between two dates.

func string(from: TimeInterval) -> String?

Returns a formatted string based on the specified number of seconds.

class func localizedString(from: DateComponents, unitsStyle: DateComponentsFormatter.UnitsStyle) -> String?

Returns a localized string based on the specified date components and style option.