Contents

Date.FormatStyle.Symbol.DayOfYear

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

Declaration

struct DayOfYear

Overview

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

Factory variable

Description

Defaultdigits

The minimum number of digits that represents the full day of the year. For example, 1, 18, 317.

Threedigits

Three-digit numeric day of the year, zero-padded if necessary. For example, 001, 018, 317.

Twodigits

Two-digit numeric day of the year, zero-padded if necessary. This format has no effect on three-digit values. For example, 01, 18, 317.

To customize the day format in a string representation of a Date, use dayOfYear(_:). The following example shows a variety of Date.FormatStyle.Symbol.DayOfYear formats applied to a date.

let meetingDate = Date() // Feb 9, 2021 at 3:00 PM
meetingDate.formatted(Date.FormatStyle().dayOfYear(.defaultDigits)) // 40
meetingDate.formatted(Date.FormatStyle().dayOfYear(.twoDigits)) // 40
meetingDate.formatted(Date.FormatStyle().dayOfYear(.threeDigits)) // 040
meetingDate.formatted(Date.FormatStyle().dayOfYear()) // 40

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 of Year Value

Comparing Day of Year Values

Type Properties

See Also

Modifying Date Style Format Symbols