Skip to content

Structure

Date.FormatStyle.Symbol.Day

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 a day in a date format style.
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

Type Properties

Type Methods

  • static func julianModified(minimumLength: Int) -> Date.FormatStyle.Symbol.Day
    The field length specifies the minimum number of digits, with zero-padding as necessary. This is different from the conventional Julian day number in two regards. First, it demarcates days at local zone midnight, rather than noon GMT. Second, it is a local number; that is, it depends on the local time zone. It can be thought of as a single number that encompasses all the date-related fields. For example, 2451334.

Relationships

Conforms To

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