Contents

Date.FormatStyle.Symbol.Month

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

Declaration

struct Month

Overview

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

Factory variable

Description

Abbreviated

Abbreviated month name. For example, Sep.

Defaultdigits

Minimum number of digits that represents the numeric month. For example, 9, 12.

Narrow

Narrow month name. For example, S.

Twodigits

Two-digit numeric month, zero-padded if necessary. For example, 09, 12.

Wide

Wide month name. For example, September.

To customize the month format in a string representation of a Date, use month(_:). The following example shows a variety of Date.FormatStyle.Symbol.Month format styles applied to a date.

let meetingDate = Date() // Feb 9, 2021 at 3:00 PM
meetingDate.formatted(Date.FormatStyle().month(.abbreviated)) // Feb
meetingDate.formatted(Date.FormatStyle().month(.narrow)) // F
meetingDate.formatted(Date.FormatStyle().month(.defaultDigits)) // 2
meetingDate.formatted(Date.FormatStyle().month(.twoDigits)) // 02
meetingDate.formatted(Date.FormatStyle().month(.wide)) // February
meetingDate.formatted(Date.FormatStyle().month()) // Feb

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 Month

Comparing a Month

Type Properties

See Also

Modifying Date Style Format Symbols