Skip to content

Structure

Date.FormatStyle.Symbol.Quarter

iOS 15.0+ iPadOS 15.0+ Mac Catalyst 15.0+ macOS 12.0+ tvOS 15.0+ watchOS 8.0+
A type that specifies the format for the quarter in a date format style.
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

Type Properties

Relationships

Conforms To

  • Swift.Equatable
  • Swift.Hashable
  • Swift.Sendable
  • Swift.SendableMetatype