<!--
{
  "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/init(secondsComponent:attosecondsComponent:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:s8DurationV16secondsComponent011attosecondsC0ABs5Int64V_AFtcfc"
  },
  "title" : "init(secondsComponent:attosecondsComponent:)"
}
-->

# init(secondsComponent:attosecondsComponent:)

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

```
init(secondsComponent: Int64, attosecondsComponent: Int64)
```

## Parameters

`secondsComponent`

The seconds component portion of the `Duration`
value.

`attosecondsComponent`

The attosecond component portion of the
`Duration` value.

## Discussion

This is useful for when an external decomposed components of a `Duration`
has been stored and needs to be reconstituted. Since the values are added
no precondition is expressed for the attoseconds being limited to 1e18.

```
  let d1 = Duration(
    secondsComponent: 3, 
    attosecondsComponent: 123000000000000000)
  print(d1) // 3.123 seconds

  let d2 = Duration(
    secondsComponent: 3, 
    attosecondsComponent: -123000000000000000)
  print(d2) // 2.877 seconds

  let d3 = Duration(
    secondsComponent: -3, 
    attosecondsComponent: -123000000000000000)
  print(d3) // -3.123 seconds
```

---

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)