Date.FormatStyle.Symbol.Week
A type that specifies the format for the week in a date format style.
Declaration
struct WeekOverview
The type Date.FormatStyle.Symbol.Week includes static factory variables that create custom Date.FormatStyle.Symbol.Week objects:
Factory variable | Description |
|---|---|
The minimum number of digits that represents the full numeric week. For example, | |
Two-digit numeric week, zero-padded if necessary. For example, | |
The numeric week of the month. For example, |
To customize the week format in a string representation of a Date, use week(_:). The following 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 week of the month 1. If no format is specified as a parameter, the defaultDigits static variable is the default format.
For more information about formatting dates, see the Date.FormatStyle.
Topics
Modifying a Week
Comparing Weeks
Type Properties
See Also
Modifying Date Style Format Symbols
Date.FormatStyle.Symbol.CyclicYearDate.FormatStyle.Symbol.DayDate.FormatStyle.Symbol.DayOfYearDate.FormatStyle.Symbol.DayPeriodDate.FormatStyle.Symbol.EraDate.FormatStyle.Symbol.HourDate.FormatStyle.Symbol.MinuteDate.FormatStyle.Symbol.MonthDate.FormatStyle.Symbol.QuarterDate.FormatStyle.Symbol.SecondDate.FormatStyle.Symbol.SecondFractionDate.FormatStyle.Symbol.StandaloneMonthDate.FormatStyle.Symbol.StandaloneQuarterDate.FormatStyle.Symbol.StandaloneWeekdayDate.FormatStyle.Symbol.TimeZone