second(_:)
Modifies the date format style to use the specified second format style.
Declaration
func second(_ format: Date.FormatStyle.Symbol.Second = .defaultDigits) -> Date.FormatStyleParameters
- format:
The second format style applied to the date format style.
Return Value
A date format style modified to include the specified second style.
Discussion
Values of Date.FormatStyle.Symbol.Second are defaultDigits and twoDigits.
This example shows a variety of Date.FormatStyle.Symbol.Second format styles applied to a date:
let meetingDate = Date() // Feb 9, 2021 at 3:05 PM
meetingDate.formatted(Date.FormatStyle().second(.defaultDigits)) // 5
meetingDate.formatted(Date.FormatStyle().second(.twoDigits)) // 05
meetingDate.formatted(Date.FormatStyle().second()) // 5If you don’t provide a format, the defaultDigits static variable is the default format.
For more information about formatting dates, see Date.FormatStyle.