Skip to content

Structure

Date.FormatStyle.Symbol.Week

iOS 15.0+ iPadOS 15.0+ Mac Catalyst 15.0+ macOS 12.0+ tvOS 15.0+ watchOS 8.0+
A type that specifies the format for the week in a date format style.
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

Type Properties

Relationships

Conforms To

  • Swift.Equatable
  • Swift.Hashable
  • Swift.Sendable
  • Swift.SendableMetatype