Contents

Date.FormatStyle.Symbol.Quarter

A type that specifies the format for the quarter in a date format style.

Declaration

struct Quarter

Overview

The type Date.FormatStyle.Symbol.Quarter includes static factory variables that create custom Date.FormatStyle.Symbol.Quarter objects:

Factory variable

Description

Abbreviated

Abbreviated quarter name. For example, Q2.

Narrow

Minimum number of digits that represents the numeric quarter. For example, 2.

Onedigit

One-digit numeric quarter. For example, 1, 4.

Twodigits

Two-digit numeric quarter, zero-padded if necessary. For example, 01, 04.

Wide

Wide quarter name. For example, 2nd quarter.

To customize the month format in a string representation of a Date, use quarter(_:). The following 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 no format is specified as a parameter, the abbreviated static variable is the default format.

For more information about formatting dates, see the Date.FormatStyle.

Topics

Modifying a Quarter

Comparing Quarters

Type Properties

See Also

Modifying Date Style Format Symbols