Contents

month(_:)

Modifies the date format style to use the specified month format style.

Declaration

func month(_ format: Date.FormatStyle.Symbol.Month = .abbreviated) -> Date.FormatStyle

Parameters

  • format:

    The month format style applied to the date format style.

Return Value

A date format style modified to include the specified month style.

Discussion

Possible values of Date.FormatStyle.Symbol.Month include abbreviated, defaultDigits, narrow, twoDigits, and wide.

This 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 you don’t provide a format, the abbreviated static variable is the default format.

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

See Also

Specifying the Date Format