<!--
{
  "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/year(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "s:10Foundation4DateV11FormatStyleV4yearyA2E6SymbolV4YearVF"
  },
  "title" : "year(_:)"
}
-->

# year(_:)

Modifies the date format style to use the specified year format style.

```
func year(_ format: Date.FormatStyle.Symbol.Year = .defaultDigits) -> Date.FormatStyle
```

## Parameters

`format`

The year format style applied to the date format style.

## Return Value

A date format style modified to include the specified year format style.

## Discussion

Possible values of [`Date.FormatStyle.Symbol.Year`](/documentation/Foundation/Date/FormatStyle/Symbol/Year) include [`twoDigits`](/documentation/Foundation/Date/FormatStyle/Symbol/Year/twoDigits), [`padded(_:)`](/documentation/Foundation/Date/FormatStyle/Symbol/Year/padded(_:)), [`relatedGregorian(minimumLength:)`](/documentation/Foundation/Date/FormatStyle/Symbol/Year/relatedGregorian(minimumLength:)), and [`extended(minimumLength:)`](/documentation/Foundation/Date/FormatStyle/Symbol/Year/extended(minimumLength:)).

This 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(.padded(6))) // 002021
```

If you don’t provide a format, the [`defaultDigits`](/documentation/Foundation/Date/FormatStyle/Symbol/Day/defaultDigits) static variable is the default format.

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

---

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)