# TimeDifferenceComplicationText.Builder

Artifact: [androidx.wear.watchface:watchface-complications-data](https://developer.android.com/jetpack/androidx/releases/wear-watchface) [View Source](https://cs.android.com/search?q=file:androidx/wear/watchface/complications/data/Text.kt+class:androidx.wear.watchface.complications.data.TimeDifferenceComplicationText.Builder) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-watchface#1.0.0)

*** ** * ** ***

Kotlin \|[Java](https://developer.android.com/reference/androidx/wear/watchface/complications/data/TimeDifferenceComplicationText.Builder "View this page in Java")


```
class TimeDifferenceComplicationText.Builder
```

<br />

*** ** * ** ***

Builder for `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/ComplicationText` representing a time difference.

Requires setting a `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/TimeDifferenceStyle`.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/TimeDifferenceComplicationText.Builder#Builder(androidx.wear.watchface.complications.data.TimeDifferenceStyle,androidx.wear.watchface.complications.data.CountDownTimeReference)( style: https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/TimeDifferenceStyle, countDownTimeReference: https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/CountDownTimeReference )` Constructs a `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/TimeDifferenceComplicationText.Builder` where the complication is counting down until `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/TimeDifferenceComplicationText.Builder#(androidx.wear.watchface.complications.data.TimeDifferenceStyle,androidx.wear.watchface.complications.data.CountDownTimeReference)`. |
| `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/TimeDifferenceComplicationText.Builder#Builder(androidx.wear.watchface.complications.data.TimeDifferenceStyle,androidx.wear.watchface.complications.data.CountUpTimeReference)( style: https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/TimeDifferenceStyle, countUpTimeReference: https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/CountUpTimeReference )` Constructs a `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/TimeDifferenceComplicationText.Builder` where the complication is counting up until `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/TimeDifferenceComplicationText.Builder#(androidx.wear.watchface.complications.data.TimeDifferenceStyle,androidx.wear.watchface.complications.data.CountUpTimeReference)`. |

| ### Public functions |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/TimeDifferenceComplicationText` | `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/TimeDifferenceComplicationText.Builder#build()()` Builds a `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/TimeDifferenceComplicationText`. |
| `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/TimeDifferenceComplicationText.Builder` | `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/TimeDifferenceComplicationText.Builder#setDisplayAsNow(kotlin.Boolean)(displayAsNow: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)` Sets whether time difference should be displayed as "now" (appropriately localized) when the given time is within the reference period. |
| `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/TimeDifferenceComplicationText.Builder` | `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/TimeDifferenceComplicationText.Builder#setMinimumTimeUnit(java.util.concurrent.TimeUnit)(minimumUnit: https://developer.android.com/reference/java/util/concurrent/TimeUnit.html?)` Sets the smallest unit that may be shown in the time difference text. |
| `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/TimeDifferenceComplicationText.Builder` | `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/TimeDifferenceComplicationText.Builder#setText(kotlin.CharSequence)(text: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-char-sequence/index.html?)` Sets the text within which the time difference will be displayed. |

## Public constructors

### Builder

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-watchface#1.0.0)

```
Builder(
    style: TimeDifferenceStyle,
    countDownTimeReference: CountDownTimeReference
)
```

Constructs a `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/TimeDifferenceComplicationText.Builder` where the complication is counting down until `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/TimeDifferenceComplicationText.Builder#(androidx.wear.watchface.complications.data.TimeDifferenceStyle,androidx.wear.watchface.complications.data.CountDownTimeReference)`.

| Parameters |
|---|---|
| `style: https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/TimeDifferenceStyle` | The `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/TimeDifferenceStyle` to use when rendering the time difference. |
| `countDownTimeReference: https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/CountDownTimeReference` | The `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/CountDownTimeReference` to count down until. |

### Builder

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-watchface#1.0.0)

```
Builder(
    style: TimeDifferenceStyle,
    countUpTimeReference: CountUpTimeReference
)
```

Constructs a `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/TimeDifferenceComplicationText.Builder` where the complication is counting up until `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/TimeDifferenceComplicationText.Builder#(androidx.wear.watchface.complications.data.TimeDifferenceStyle,androidx.wear.watchface.complications.data.CountUpTimeReference)`.

| Parameters |
|---|---|
| `style: https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/TimeDifferenceStyle` | The `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/TimeDifferenceStyle` to use when rendering the time difference. |
| `countUpTimeReference: https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/CountUpTimeReference` | The `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/CountUpTimeReference` to count up until. |

## Public functions

### build

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-watchface#1.0.0)

```
fun build(): TimeDifferenceComplicationText
```

Builds a `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/TimeDifferenceComplicationText`.

### setDisplayAsNow

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-watchface#1.0.0)

```
fun setDisplayAsNow(displayAsNow: Boolean): TimeDifferenceComplicationText.Builder
```

Sets whether time difference should be displayed as "now" (appropriately localized) when the given time is within the reference period. If false, then text representing zero (e.g. `0 mins` or `00:00`) will be shown instead.

The default is true for all styles except for `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/TimeDifferenceStyle#STOPWATCH`.

### setMinimumTimeUnit

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-watchface#1.0.0)

```
fun setMinimumTimeUnit(minimumUnit: TimeUnit?): TimeDifferenceComplicationText.Builder
```

Sets the smallest unit that may be shown in the time difference text. If specified, units smaller than this minimum will not be included.

For example, if this is set to `https://developer.android.com/reference/java/util/concurrent/TimeUnit.html#HOURS`, and the style is `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/TimeDifferenceStyle#SHORT_SINGLE_UNIT` then `12d` or `5h` would be shown as normal, but `35m` would be shown as `1h`.

If not specified the style will determine the smallest unit that will be shown.

If the specified minimum is smaller than the smallest unit supported by the style, then the minimum will be ignored. For example, if the style is `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/TimeDifferenceStyle#SHORT_SINGLE_UNIT`, then a minimum unit of `https://developer.android.com/reference/java/util/concurrent/TimeUnit.html#SECONDS` will have no effect.

### setText

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-watchface#1.0.0)

```
fun setText(text: CharSequence?): TimeDifferenceComplicationText.Builder
```

Sets the text within which the time difference will be displayed.

Within the text, `^1` will be replaced with the time difference, so for example to show a result like `"2 mins: meeting"` the text would be `"^1: meeting"`

To use the `^` character within the text, escape it as `^^`.

The text may contain spans, but the watch face is not required to respect them. The watch face is allowed to treat `https://developer.android.com/reference/android/text/style/ForegroundColorSpan.html` as a hint that it should render the affected text with an alternative color of its choosing.

The allowed spans are `https://developer.android.com/reference/android/text/style/ForegroundColorSpan.html`, `https://developer.android.com/reference/android/text/style/LocaleSpan.html`, `https://developer.android.com/reference/android/text/style/SubscriptSpan.html`, `https://developer.android.com/reference/android/text/style/SuperscriptSpan.html`, `https://developer.android.com/reference/android/text/style/StyleSpan.html`, `https://developer.android.com/reference/android/text/style/StrikethroughSpan.html`, `https://developer.android.com/reference/android/text/style/TypefaceSpan.html` and `https://developer.android.com/reference/android/text/style/UnderlineSpan.html`.