---
title: "time(pattern:)"
framework: foundation
role: symbol
role_heading: Type Method
path: "foundation/formatstyle/time(pattern:)"
---

# time(pattern:)

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

## Declaration

```swift
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

Return Value A duration time format style customized with the specified pattern.

## Discussion

Discussion Use the dot-notation form of this type method when the call point allows the use of Duration.TimeFormatStyle. You typically do this when calling the formatted(_:) method of Duration. The following example creates a duration to represent 1 hour, 10 minutes, 32 seconds, and 400 milliseconds. It then uses time(pattern:) to customize a 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 formatted(_:) method, the resulting string is 01:10:32.40. 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"

## See Also

### Applying duration styles

- [timeDuration](foundation/formatstyle/timeduration.md)
- [Date.ComponentsFormatStyle](foundation/date/componentsformatstyle.md)
- [units(allowed:width:maximumUnitCount:zeroValueUnits:valueLength:fractionalPart:)](foundation/formatstyle/units(allowed:width:maximumunitcount:zerovalueunits:valuelength:fractionalpart:).md)
- [units(allowed:width:maximumUnitCount:zeroValueUnits:valueLengthLimits:fractionalPart:)](foundation/formatstyle/units(allowed:width:maximumunitcount:zerovalueunits:valuelengthlimits:fractionalpart:).md)
