Contents

Date.FormatStyle.Symbol.Week

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

Declaration

struct Week

Overview

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

Factory variable

Description

Defaultdigits

The minimum number of digits that represents the full numeric week. For example, 1, 18.

Twodigits

Two-digit numeric week, zero-padded if necessary. For example, 01, 18.

Weekofmonth

The numeric week of the month. For example, 1, 4.

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