A struct representing a time value such as a timestamp or duration.

Language

- Swift
- Objective-C

SDKs

- iOS 4.0+
- macOS 10.7+
- tvOS 9.0+
- Xcode 6.3+

## Overview

This document describes the API for creating and manipulating `CMTime`

structs.

`CMTime`

structs are non-opaque mutable structs representing times (either timestamps or durations).

A `CMTime`

is represented as a rational number, with a numerator (an `int64_t`

value), and a denominator (an `int32_t`

timescale). Conceptually, the timescale specifies the fraction of a second each unit in the numerator occupies. Thus if the timescale is 4, each unit represents a quarter of a second; if the timescale is 10, each unit represents a tenth of a second, and so on. In addition to a simple time value, a CMTime can represent non-numeric values: +infinity, -infinity, and indefinite. Using a flag CMTime indicates whether the time been rounded at some point.

`CMTimes`

contain an epoch number, which is usually set to 0, but can be used to distinguish unrelated timelines: for example, it could be incremented each time through a presentation loop, to differentiate between time N in loop 0 from time N in loop 1.

You can convert `CMTimes`

to and from immutable CFDictionaries (see `CFDictionary`

) using `CMTime`

and `CMTime`

, for use in annotations and various Core Foundation containers.

Additional functions for managing dates and times are described in Time Utilities. Note that `CMTime`

is designed for media timelines whereas functions in `Time Utilities Reference`

are designed for working with wall-clock time in Core Foundation framework; see also AVFoundation Constants.