<!--
{
  "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" : "Foundation",
  "identifier" : "/documentation/Foundation/FormatStyle/time(pattern:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "s:10Foundation11FormatStylePAAs8DurationVAAE04TimebC0VRszrlE4time7patternA2G7PatternV_tFZ"
  },
  "title" : "time(pattern:)"
}
-->

# time(pattern:)

Returns a style for formatting a duration using a provided pattern.

```
static func time(pattern: Duration.TimeFormatStyle.Pattern) -> Self
```

## Parameters

`pattern`

A <doc://com.apple.documentation/documentation/Swift/Duration/TimeFormatStyle/Pattern-swift.struct> that specifies the units to include in the displayed string and the behavior of the units.

## Return Value

A duration time format style customized with the specified pattern.

## Discussion

Use the dot-notation form of this type method when the call point allows the use of <doc://com.apple.documentation/documentation/Swift/Duration/TimeFormatStyle>. You typically do this when calling the <doc://com.apple.documentation/documentation/Swift/Duration/formatted(_:)> method of <doc://com.apple.documentation/documentation/Swift/Duration>.

The following example creates a duration to represent 1 hour, 10 minutes, 32 seconds, and 400 milliseconds. It then uses [`time(pattern:)`](/documentation/Foundation/FormatStyle/time(pattern:)) to customize a <doc://com.apple.documentation/documentation/Swift/Duration/TimeFormatStyle> to show hours, minutes, and seconds, padding the hours part to two digits and limiting the fractional seconds to two digits. When used with the <doc://com.apple.documentation/documentation/Swift/Duration/formatted(_:)> method, the resulting string is `01:10:32.40`.

```swift
let duration = Duration.seconds(70 * 60 + 32) + Duration.milliseconds(400)
let format = duration.formatted(
    .time(pattern: .hourMinuteSecond(padHourToLength: 2,
                                     fractionalSecondsLength: 2)))
// format == "01:10:32.40"
```

---

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)