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

# Date.AttributedStyle

A structure that creates a locale-appropriate attributed string representation of a date instance.

```
struct AttributedStyle
```

## Overview

Use a [`Date.FormatStyle`](/documentation/Foundation/Date/FormatStyle) instance to customize the lexical representation of a date as a string. Use the format style’s [`attributed`](/documentation/Foundation/Date/FormatStyle/attributed-swift.property) property to customize the visual representation of the date as a string. Attributed strings can represent the subcomponent characters, words, and phrases of a string with a custom combination of font size, weight, and color.

For example, the function below uses a date format style to create a custom lexical representation of a date, then retrieves an attributed string representation of the same date and applies a visual emphasis to the year component of the date.

```swift
// Applies visual emphasis to the year component of a formatted attributed date string.
private func makeAttributedString() -> AttributedString {
    let date = Date()
    let formatStyle = Date.FormatStyle(date: .abbreviated, time: .standard)
    var attributedString = formatStyle.attributed.format(date)
    for run in attributedString.runs {
        if let dateFieldAttribute = run.attributes.foundation.dateField,
           dateFieldAttribute == .year {
            // When you find a year, change its attributes.
            attributedString[run.range].inlinePresentationIntent = [.emphasized, .stronglyEmphasized]
        }
    }
    return attributedString
}
```

The expression `formatStyle.attributed.format(date)` above creates an attributed string representation of the date. This assigns instances of the [`AttributeScopes.FoundationAttributes.DateFieldAttribute`](/documentation/Foundation/AttributeScopes/FoundationAttributes/DateFieldAttribute) to indicate ranges of the string that represent different date fields. The example then loops over the [`runs`](/documentation/Foundation/AttributedStringProtocol/runs) of the attributed string to find any run with the [`AttributeScopes.FoundationAttributes.DateFieldAttribute.Field.year`](/documentation/Foundation/AttributeScopes/FoundationAttributes/DateFieldAttribute/Field/year) attribute. When it finds one, it adds the [`inlinePresentationIntent`](/documentation/Foundation/AttributeScopes/FoundationAttributes/inlinePresentationIntent) attributes [`emphasized`](/documentation/Foundation/InlinePresentationIntent/emphasized) and [`stronglyEmphasized`](/documentation/Foundation/InlinePresentationIntent/stronglyEmphasized).

The runs of the resulting attributed string have the following attributes:

|Run text|Attributes                                                                                                                                                                                                                                                                                                                                        |
|--------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|`Mar`   |``doc://com.apple.foundation/documentation/Foundation/AttributeScopes/FoundationAttributes/DateFieldAttribute/Field/month``                                                                                                                                                                                                                       |
|`15`    |``doc://com.apple.foundation/documentation/Foundation/AttributeScopes/FoundationAttributes/DateFieldAttribute/Field/day``                                                                                                                                                                                                                         |
|`2022`  |``doc://com.apple.foundation/documentation/Foundation/AttributeScopes/FoundationAttributes/DateFieldAttribute/Field/year`` ![](spacer) ``doc://com.apple.foundation/documentation/Foundation/InlinePresentationIntent/emphasized`` ![](spacer) ``doc://com.apple.foundation/documentation/Foundation/InlinePresentationIntent/stronglyEmphasized``|
|`10`    |``doc://com.apple.foundation/documentation/Foundation/AttributeScopes/FoundationAttributes/DateFieldAttribute/Field/hour``                                                                                                                                                                                                                        |
|`06`    |``doc://com.apple.foundation/documentation/Foundation/AttributeScopes/FoundationAttributes/DateFieldAttribute/Field/minute``                                                                                                                                                                                                                      |
|`46`    |``doc://com.apple.foundation/documentation/Foundation/AttributeScopes/FoundationAttributes/DateFieldAttribute/Field/second``                                                                                                                                                                                                                      |
|`AM`    |``doc://com.apple.foundation/documentation/Foundation/AttributeScopes/FoundationAttributes/DateFieldAttribute/Field/amPM``                                                                                                                                                                                                                        |

If you create a SwiftUI <doc://com.apple.documentation/documentation/SwiftUI/Text> view with this attributed string, SwiftUI renders the combination of [`emphasized`](/documentation/Foundation/InlinePresentationIntent/emphasized) and [`stronglyEmphasized`](/documentation/Foundation/InlinePresentationIntent/stronglyEmphasized) attributes as bold, italicized text, as seen in the following screenshot.

![A macOS window with a text view showing the current date and time. The year is displayed in bold, italicized text.](images/com.apple.foundation/media-3957719@2x.png)

## Topics

### Modifying a Date Attributed Style

[`func locale(Locale) -> Date.AttributedStyle`](/documentation/Foundation/Date/AttributedStyle/locale(_:))

Modifies the date attributed style to use the specified locale.

### Applying Date Attributed Styles

[`func format(Date) -> AttributedString`](/documentation/Foundation/Date/AttributedStyle/format(_:))

Creates a locale-aware attributed string representation from a date value.

### Supporting Types

### Comparing Date Attributed Styles

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

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

## Relationships

### Conforms To

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

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

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

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

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

[`FormatStyle`](/documentation/Foundation/FormatStyle)

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

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

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

---

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)