<!--
{
  "availability" : [
    "iOS: 15.0.0 -",
    "iPadOS: 15.0.0 -",
    "macCatalyst: 15.0.0 -",
    "macOS: 12.0.0 -",
    "tvOS: 15.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 8.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/Date/FormatStyle/Symbol/Year",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "s:10Foundation4DateV11FormatStyleV6SymbolV4YearV"
  },
  "title" : "Date.FormatStyle.Symbol.Year"
}
-->

# Date.FormatStyle.Symbol.Year

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

```
struct Year
```

## Overview

The [`Date.FormatStyle.Symbol.Year`](/documentation/Foundation/Date/FormatStyle/Symbol/Year) type includes static factory variables and methods that create custom [`Date.FormatStyle.Symbol.Year`](/documentation/Foundation/Date/FormatStyle/Symbol/Year) objects:

|Factory variable                                                                                                     |Description                                                                                                                                                                        |
|---------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|``doc://com.apple.foundation/documentation/Foundation/Date/FormatStyle/Symbol/Year/defaultDigits``                   |The minimum number of digits that represents the full year. For example, `2`, `20`, `201`, `2017`.                                                                                 |
|``doc://com.apple.foundation/documentation/Foundation/Date/FormatStyle/Symbol/Year/twoDigits``                       |The year’s two lowest-order digits, zero-padded or truncated if necessary. For example, `02`, `20`, `01`, `17`, `73`.                                                              |
|``doc://com.apple.foundation/documentation/Foundation/Date/FormatStyle/Symbol/Year/padded(_:)``                      |Three or more digits, zero-padded if necessary. For example, `002`, `020`, `201`, `2017`.                                                                                          |
|``doc://com.apple.foundation/documentation/Foundation/Date/FormatStyle/Symbol/Year/relatedGregorian(minimumLength:)``|For non-Gregorian calendars, output corresponds to the extended Gregorian year in which the calendar’s year begins. The default length is the minimum needed to show the full year.|
|``doc://com.apple.foundation/documentation/Foundation/Date/FormatStyle/Symbol/Year/extended(minimumLength:)``        |A single number designating the year of the calendar system, encompassing all supra-year fields. The default length is the minimum needed to show the full year.                   |

To customize the year format in a string representation of a `Date`, use [`year(_:)`](/documentation/Foundation/Date/FormatStyle/year(_:)). The following example shows a variety of [`Date.FormatStyle.Symbol.Year`](/documentation/Foundation/Date/FormatStyle/Symbol/Year) formats applied to a date.

```swift
let meetingDate = Date() // Feb 9, 2021 at 3:00 PM
meetingDate.formatted(Date.FormatStyle().year(.defaultDigits)) // 2021
meetingDate.formatted(Date.FormatStyle().year(.twoDigits)) // 21
meetingDate.formatted(Date.FormatStyle().year(.extended(minimumLength: 5))) // 02021
meetingDate.formatted(Date.FormatStyle().year(.extended())) // 2021
meetingDate.formatted(Date.FormatStyle().year(.padded(6))) // 002021
meetingDate.formatted(Date.FormatStyle().year(.relatedGregorian())) // 2021
```

If no format is specified as a parameter, the [`defaultDigits`](/documentation/Foundation/Date/FormatStyle/Symbol/Day/defaultDigits) static variable is the default format.

For more information about formatting dates, see the [`Date.FormatStyle`](/documentation/Foundation/Date/FormatStyle).

## Topics

### Modifying a Year

[`static var defaultDigits: Date.FormatStyle.Symbol.Year`](/documentation/Foundation/Date/FormatStyle/Symbol/Year/defaultDigits)

The custom year format style showing the minimum number of digits that represents the numeric year.

[`static var twoDigits: Date.FormatStyle.Symbol.Year`](/documentation/Foundation/Date/FormatStyle/Symbol/Year/twoDigits)

The custom format style portraying the two-digit numeric year, zero-padded if necessary.

[`static func padded(Int) -> Date.FormatStyle.Symbol.Year`](/documentation/Foundation/Date/FormatStyle/Symbol/Year/padded(_:))

Returns a custom format style that portrays the year of the calendar system of the provided length, zero-padded if necessary.

[`static func relatedGregorian(minimumLength: Int) -> Date.FormatStyle.Symbol.Year`](/documentation/Foundation/Date/FormatStyle/Symbol/Year/relatedGregorian(minimumLength:))

Returns a custom format style that portrays the year of a non-Gregorian calendar system in the corresponding Gregorian year.

[`static func extended(minimumLength: Int) -> Date.FormatStyle.Symbol.Year`](/documentation/Foundation/Date/FormatStyle/Symbol/Year/extended(minimumLength:))

Returns a custom format style that portrays the year of the calendar system, encompassing all supra-year fields.

### Comparing Years

[`static func == (Date, Date) -> Bool`](/documentation/Foundation/Date/==(_:_:))

Returns true if the two `Date` values represent the same point in time.

### Type Properties

[`static let omitted: Date.FormatStyle.Symbol.Year`](/documentation/Foundation/Date/FormatStyle/Symbol/Year/omitted)

The option for not including the symbol in the formatted output.

## Relationships

### Conforms To

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

[`Hashable`](/documentation/Swift/Hashable)

[`Equatable`](/documentation/Swift/Equatable)

[`Sendable`](/documentation/Swift/Sendable)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)