Contents

day(_:)

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

Declaration

func day(_ format: Date.FormatStyle.Symbol.Day = .defaultDigits) -> Date.FormatStyle

Parameters

  • format:

    The day format style applied to the date format style.

Return Value

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

Discussion

Possible values of Date.FormatStyle.Symbol.Day are defaultDigits, ordinalOfDayInMonth, and twoDigits.

This example shows a variety of Date.FormatStyle.Symbol.Day formats applied to a date:

let meetingDate = Date() // Feb 9, 2021 at 3:00 PM
meetingDate.formatted(Date.FormatStyle().day(.defaultDigits)) // 9
meetingDate.formatted(Date.FormatStyle().day(.ordinalOfDayInMonth)) // 2 (second Tuesday of the month)
meetingDate.formatted(Date.FormatStyle().day(.twoDigits)) // 09
meetingDate.formatted(Date.FormatStyle().day()) // 9

If you don’t provide a format, the defaultDigits static variable is the default format.

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

See Also

Specifying the Date Format