<!--
{
  "availability" : [
    "iOS: 4.0.0 -",
    "iPadOS: 4.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.7.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 6.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreMedia",
  "identifier" : "/documentation/CoreMedia/CMTimeAdd(_:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Core Media"
    ],
    "preciseIdentifier" : "c:@F@CMTimeAdd"
  },
  "title" : "CMTimeAdd(_:_:)"
}
-->

# CMTimeAdd(_:_:)

Returns the sum of two times.

```
func CMTimeAdd(_ lhs: CMTime, _ rhs: CMTime) -> CMTime
```

## Parameters

`lhs`

A time value.

`rhs`

A second time value.

## Return Value

A time value that represents the result of the operation.

## Discussion

If both operands have the same timescale, the timescale of the result is the same. If the operands have different timescales, the timescale of the result is the least common multiple of the operands’ timescales. If that value is greater than [`kCMTimeMaxTimescale`](/documentation/CoreMedia/kCMTimeMaxTimescale), the system sets the timescale to [`kCMTimeMaxTimescale`](/documentation/CoreMedia/kCMTimeMaxTimescale) and uses the default rounding method to convert the result to this timescale.

If the value of the result overflows, the system repeatedly halves its timescale until it no longer overflows, and uses the default rounding to convert the result to this timescale. If the result’s value still overflows when its timescale is `1`, the system sets the result’s timescale to positive or negative infinity, depending on the direction of the overflow. If any rounding occurs, or if either operand has its [`hasBeenRounded`](/documentation/CoreMedia/CMTimeFlags/hasBeenRounded) flag set, the system sets the result’s [`hasBeenRounded`](/documentation/CoreMedia/CMTimeFlags/hasBeenRounded) flag.

If either of the operands is [`invalid`](/documentation/CoreMedia/CMTime/invalid), the result is [`invalid`](/documentation/CoreMedia/CMTime/invalid).

If the operands are valid, but one is infinite, the result is infinite. If the operands are valid, and both are infinite, the results are as follows:

- +infinity + +infinity == +infinity
- -infinity + -infinity == -infinity
- +infinity + -infinity == invalid
- -infinity + +infinity == invalid

If the operands are valid, not infinite, and either or both is [`indefinite`](/documentation/CoreMedia/CMTime/indefinite), the result is [`indefinite`](/documentation/CoreMedia/CMTime/indefinite).

If the two operands are numeric, but have different nonzero epochs, the result is [`invalid`](/documentation/CoreMedia/CMTime/invalid). If both have the same nonzero epoch, the result is epoch zero. You can’t add or subtract times that have different epochs, because the epoch length is unknown. The system considers times in epoch zero to be durations, so you can add them to times in other epochs. You can compare times in different epochs, however, because numerically greater epochs always occur after numerically lesser epochs.

---

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)