quarter(_:)
Modifies the date format style to use the specified quarter format style.
Declaration
func quarter(_ format: Date.FormatStyle.Symbol.Quarter = .abbreviated) -> Date.FormatStyleParameters
- format:
The quarter format style applied to the date format style.
Return Value
A date format style modified to include the specified quarter style.
Discussion
Possible values of Date.FormatStyle.Symbol.Quarter include abbreviated, narrow, oneDigit, twoDigits, and wide.
This example shows a variety of Date.FormatStyle.Symbol.Quarter format styles applied to a date:
let meetingDate = Date() // Oct 7, 2020 at 3:00 PM
meetingDate.formatted(Date.FormatStyle().quarter(.abbreviated)) // Q4
meetingDate.formatted(Date.FormatStyle().quarter(.narrow)) // 4th quarter
meetingDate.formatted(Date.FormatStyle().quarter(.oneDigit)) // 4
meetingDate.formatted(Date.FormatStyle().quarter(.twoDigits)) // 04
meetingDate.formatted(Date.FormatStyle().quarter(.wide)) // 4th quarter
meetingDate.formatted(Date.FormatStyle().quarter()) // Q4
If you don’t provide a format, the abbreviated static variable is the default format.
For more information about formatting dates, see Date.FormatStyle.