Type Method

localizedString(from:dateStyle:timeStyle:)

Returns a string representation of a given date, formatted for the current locale using the specified date and time styles.

Declaration

class func localizedString(from date: Date, dateStyle dstyle: DateFormatter.Style, timeStyle tstyle: DateFormatter.Style) -> String

Parameters

date

A date.

dateStyle

A format style for the date. For possible values, see DateFormatter.Style.

timeStyle

A format style for the time. For possible values, see DateFormatter.Style.

Return Value

A localized string representation of date using the specified date and time styles.

Discussion

This method uses a date formatter configured with the current default settings. The returned string is the same as if you configured and used a date formatter as shown in the following example:

let formatter = DateFormatter()
formatter.formatterBehavior = .behavior10_4
formatter.dateStyle = dateStyle
formatter.timeStyle = timeStyle
let result = formatter.string(from: date)

See Also

Converting Objects

func date(from: String) -> Date?

Returns a date representation of a given string interpreted using the receiver’s current settings.

func string(from: Date) -> String

Returns a string representation of a given date formatted using the receiver’s current settings.

func getObjectValue(AutoreleasingUnsafeMutablePointer<AnyObject?>?, for: String, range: UnsafeMutablePointer<NSRange>?)

Returns by reference a date representation of a given string and the range of the string used, and returns a Boolean value that indicates whether the string could be parsed.