Contents

week(_:)

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

Declaration

func week(_ format: Date.FormatStyle.Symbol.Week = .defaultDigits) -> Date.FormatStyle

Parameters

  • format:

    The week format style applied to the date format style.

Return Value

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

Discussion

Possible values of Date.FormatStyle.Symbol.Week include defaultDigits, twoDigits, and weekOfMonth.

This example shows a variety of Date.FormatStyle.Symbol.Week format styles applied to a date:

let meetingDate = Date() // May 3, 2021 at 3:00 PM
meetingDate.formatted(Date.FormatStyle().week(.defaultDigits)) // 19
meetingDate.formatted(Date.FormatStyle().week(.twoDigits)) // 19
meetingDate.formatted(Date.FormatStyle().week(.weekOfMonth)) // 2
meetingDate.formatted(Date.FormatStyle().week()) // 19

An incomplete week at the start of a month is the first week of the month 1. 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