<!--
{
  "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",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:s8DurationV"
  },
  "title" : "Duration"
}
-->

# Duration

A representation of high precision time.

```
@frozen struct Duration
```

## Overview

`Duration` represents an elapsed time value with high precision in an
integral form. It may be used for measurements of varying clock sources. In
those cases it represents the elapsed time measured by that clock.
Calculations using `Duration` may span from a negative value to a positive
value and have a suitable range to at least cover attosecond scale for both
small elapsed durations like sub-second precision to durations that span
centuries.

Typical construction of `Duration` values should be created via the
static methods for specific time values.

```
 var d: Duration = .seconds(3)
 d += .milliseconds(33)
 print(d) // 3.033 seconds
```

`Duration` itself does not ferry any additional information other than the
temporal measurement component; specifically leap seconds should be
represented as an additional accessor since that is specific only to certain
clock implementations.

## Topics

### Creating a duration

[`init(secondsComponent:attosecondsComponent:)`](/documentation/Swift/Duration/init(secondsComponent:attosecondsComponent:))

Construct a `Duration` by adding attoseconds to a seconds value.

[`seconds(_:)`](/documentation/Swift/Duration/seconds(_:)-311cx)

Construct a `Duration` given a number of seconds represented as a
`BinaryInteger`.

[`seconds(_:)`](/documentation/Swift/Duration/seconds(_:)-5ifzr)

Construct a `Duration` given a number of seconds represented as a
`Double` by converting the value into the closest attosecond scale value.

[`milliseconds(_:)`](/documentation/Swift/Duration/milliseconds(_:)-1w328)

Construct a `Duration` given a number of milliseconds represented as a
`BinaryInteger`.

[`milliseconds(_:)`](/documentation/Swift/Duration/milliseconds(_:)-7ledy)

Construct a `Duration` given a number of seconds milliseconds as a
`Double` by converting the value into the closest attosecond scale value.

[`microseconds(_:)`](/documentation/Swift/Duration/microseconds(_:)-1zzcc)

Construct a `Duration` given a number of seconds microseconds as a
`Double` by converting the value into the closest attosecond scale value.

[`microseconds(_:)`](/documentation/Swift/Duration/microseconds(_:)-2majo)

Construct a `Duration` given a number of microseconds represented as a
`BinaryInteger`.

### Accessing a duration’s components

[`components`](/documentation/Swift/Duration/components)

The composite components of the `Duration`.

### Performing calculations on durations

[`*(_:_:)`](/documentation/Swift/Duration/*(_:_:)-3d469)

[`*=(_:_:)`](/documentation/Swift/Duration/*=(_:_:))

[`/(_:_:)`](/documentation/Swift/Duration/_(_:_:)-7fkmh)

[`/=(_:_:)`](/documentation/Swift/Duration/_=(_:_:)-10rgx)

[`/=(_:_:)`](/documentation/Swift/Duration/_=(_:_:)-1qfv3)

### Formatting a duration

[`formatted()`](/documentation/Swift/Duration/formatted())

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

[`formatted(_:)`](/documentation/Swift/Duration/formatted(_:))

Formats the duration, using the provided format style.

[`Duration.TimeFormatStyle`](/documentation/Swift/Duration/TimeFormatStyle)

A format style that shows durations in a compact, localized format with separators.

[`Duration.UnitsFormatStyle`](/documentation/Swift/Duration/UnitsFormatStyle)

A format style that shows durations with localized labeled components



---

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)