<!--
{
  "availability" : [
    "iOS: 16.0.0 -",
    "iPadOS: 16.0.0 -",
    "macCatalyst: 16.0.0 -",
    "macOS: 13.0.0 -",
    "tvOS: 16.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 9.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/Duration/formatted()",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:s8DurationV10FoundationE9formattedSSyF"
  },
  "title" : "formatted()"
}
-->

# formatted()

Formats the string using a localized hour-minute-second time pattern.

```
func formatted() -> String
```

## Return Value

A localized formatted string that describes the duration, such as `1:30:56` for a duration of 1 hour, 30 minutes, and 56 seconds in the U.S. English locale. In the Finnish locale, this returns `1.30.56`.

## Discussion

The following example shows the effect of applying the default formatting to a duration of two seconds:

```
let duration = Duration.seconds(2)
let formattedDuration = duration.formatted() // "0:00:02"
```

This method uses a default [`Duration.TimeFormatStyle`](/documentation/Swift/Duration/TimeFormatStyle). To modify the formatting, customize a [`Duration.TimeFormatStyle`](/documentation/Swift/Duration/TimeFormatStyle) or [`Duration.UnitsFormatStyle`](/documentation/Swift/Duration/UnitsFormatStyle), then call [`formatted(_:)`](/documentation/Swift/Duration/formatted(_:)) on the duration, passing in the style. You can also call `format(_:)` on the style, passing in a duration.

---

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)