Contents

Date.FormatStyle.Symbol.Day

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

Declaration

struct Day

Overview

The Date.FormatStyle.Symbol.Day type includes static factory variables and methods that create custom Date.FormatStyle.Symbol.Day objects:

Factory variable

Description

Defaultdigits

The minimum number of digits that shows the numeric day of month. For example, 1, 18.

Julianmodified(minimumlength:)

The modified Julian day. The field length specifies the minimum number of digits, zero-padded if necessary. For example, 2451334.

Ordinalofdayinmonth

The ordinal of the day in the month. For example, the second Wednesday in July would yield 2.

Twodigits

The two-digit numeric day of month, zero-padded if necessary. For example, 01, 18.

To customize the day format in a string representation of a Date, use day(_:). The following 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(.julianModified(minimumLength: 12))) // 0002459255
meetingDate.formatted(Date.FormatStyle().day()) // 9

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 Day Format

Comparing Day Formats

Type Properties

See Also

Modifying Date Style Format Symbols