formatted()
Generates a locale-aware string representation of a date using the default date format style.
Declaration
func formatted() -> StringReturn Value
A string, formatted according to the default style.
Discussion
Use the formatted() method to apply the default format style to a date, as in the following example:
let birthday = Date()
print(birthday.formatted())
// 6/4/2021, 2:24 PMThe default date format style uses the numeric date style and the shortened time style.
To customize the formatted measurement string, use either the formatted(_:) method and include a Measurement.FormatStyle or the formatted(date:time:) and include a date and time style.
For more information about formatting dates, see Date.FormatStyle.