# NotificationCompat.Metric.TimeDifference

Artifact: [androidx.core:core](https://developer.android.com/jetpack/androidx/releases/core) [View Source](https://cs.android.com/search?q=file:androidx/core/app/NotificationCompat.java+class:androidx.core.app.NotificationCompat.Metric.TimeDifference) Added in [1.19.1](https://developer.android.com/jetpack/androidx/releases/core#1.19.1)

*** ** * ** ***


```
class NotificationCompat.Metric.TimeDifference : NotificationCompat.Metric.MetricValue
```

<br />

|---|---|---|
| [kotlin.Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html) |||
| ↳ | [androidx.core.app.NotificationCompat.Metric.MetricValue](https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Metric.MetricValue) ||
|   | ↳ | [androidx.core.app.NotificationCompat.Metric.TimeDifference](https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Metric.TimeDifference) |

*** ** * ** ***

This represents a timer, a stopwatch, or a countdown to an event.

When representing a *running* timer (or stopwatch, etc), this value specifies a reference instant for when that timer will hit zero (or the stopwatch was at zero, respectively), called the "zero time". In this case the time displayed is defined as the difference between the "zero time" and the current time, meaning it will show a live-updated timer.

The zero time can be specified as an `https://developer.android.com/reference/java/time/Instant.html` (in which case it corresponds to a "real-world" point in time, from `https://developer.android.com/reference/java/time/InstantSource.html#system()`), or as milliseconds since boot (from `https://developer.android.com/reference/android/os/SystemClock.html#elapsedRealtime()`). The latter might be suitable when the timer is tied to an `https://developer.android.com/reference/android/app/AlarmManager.html#ELAPSED_REALTIME` alarm in `https://developer.android.com/reference/android/app/AlarmManager.html`.

When representing a *paused* timer (or stopwatch, etc), this value specifies the duration as a fixed value.

This value can also specify its formatting, whether as a "chronometer" (e.g. 43:21) or an adaptive time (e.g. 1h 43m).

## Summary

| ### Constants |
|---|---|
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Metric.TimeDifference#FORMAT_ADAPTIVE() = 1` Formatting option: adaptive (e.g. 1h 5m; 15m; 1m 30s; 5s). |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Metric.TimeDifference#FORMAT_CHRONOMETER() = 2` Formatting option: chronometer-style, (e.g. two hours = "2:00:00"). |

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Metric.TimeDifference#equals(java.lang.Object)(obj: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html!)` |
| `java-static https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Metric.TimeDifference` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 37) https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Metric.TimeDifference#forPausedStopwatch(java.time.Duration,int)(elapsedTime: https://developer.android.com/reference/java/time/Duration.html, format: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Creates a "paused stopwatch" metric, showing the `elapsedTime`. |
| `java-static https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Metric.TimeDifference` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 37) https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Metric.TimeDifference#forPausedTimer(java.time.Duration,int)(remainingTime: https://developer.android.com/reference/java/time/Duration.html, format: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Creates a "paused timer" metric, showing the `remainingTime`. |
| `java-static https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Metric.TimeDifference` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 37) https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Metric.TimeDifference#forStopwatch(java.time.Instant,int)(startTime: https://developer.android.com/reference/java/time/Instant.html, format: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Creates a "running stopwatch" metric, which will show the time elapsed since `startTime`. |
| `java-static https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Metric.TimeDifference` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 37) https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Metric.TimeDifference#forStopwatch(long,int)(startTime: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html, format: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Creates a "running stopwatch" metric, which will show the time elapsed since `startTime`, specified in the `https://developer.android.com/reference/android/os/SystemClock.html#elapsedRealtime()` frame of reference. |
| `java-static https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Metric.TimeDifference` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 37) https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Metric.TimeDifference#forTimer(java.time.Instant,int)(endTime: https://developer.android.com/reference/java/time/Instant.html, format: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Creates a "running timer" metric, which will show a countdown to `endTime`. |
| `java-static https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Metric.TimeDifference` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 37) https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Metric.TimeDifference#forTimer(long,int)(endTime: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html, format: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Creates a "running timer" metric, which will show a countdown to `endTime`, specified in the `https://developer.android.com/reference/android/os/SystemClock.html#elapsedRealtime()` frame of reference. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Metric.TimeDifference#getFormat()()` Formatting option for the timer/stopwatch. |
| `https://developer.android.com/reference/java/time/Duration.html?` | `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Metric.TimeDifference#getPausedDuration()()` The fixed time difference, for a paused timer or stopwatch. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html?` | `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Metric.TimeDifference#getZeroElapsedRealtime()()` The elapsed realtime at which the time difference is zero. |
| `https://developer.android.com/reference/java/time/Instant.html?` | `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Metric.TimeDifference#getZeroTime()()` The `https://developer.android.com/reference/java/time/Instant.html` at which the time difference is zero. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Metric.TimeDifference#hashCode()()` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Metric.TimeDifference#isStopwatch()()` Whether this `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Metric.TimeDifference` value represents a stopwatch -- when running, it counts up from `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Metric.TimeDifference#getZeroTime()` (or `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Metric.TimeDifference#getZeroElapsedRealtime()`). |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Metric.TimeDifference#isTimer()()` Whether this `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Metric.TimeDifference` value represents a timer -- when running, it counts down to `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Metric.TimeDifference#getZeroTime()` (or `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Metric.TimeDifference#getZeroElapsedRealtime()`). |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Metric.TimeDifference#toString()()` |

## Constants

### FORMAT_ADAPTIVE

Added in [1.19.1](https://developer.android.com/jetpack/androidx/releases/core#1.19.1)

```
const val FORMAT_ADAPTIVE = 1: Int
```

Formatting option: adaptive (e.g. 1h 5m; 15m; 1m 30s; 5s).

### FORMAT_CHRONOMETER

Added in [1.19.1](https://developer.android.com/jetpack/androidx/releases/core#1.19.1)

```
const val FORMAT_CHRONOMETER = 2: Int
```

Formatting option: chronometer-style, (e.g. two hours = "2:00:00").

## Public functions

### equals

```
fun equals(obj: Any!): Boolean
```

### forPausedStopwatch

Added in [1.19.1](https://developer.android.com/jetpack/androidx/releases/core#1.19.1)

```
@RequiresApi(value = 37)
java-static fun forPausedStopwatch(elapsedTime: Duration, format: Int): NotificationCompat.Metric.TimeDifference
```

Creates a "paused stopwatch" metric, showing the `elapsedTime`.

### forPausedTimer

Added in [1.19.1](https://developer.android.com/jetpack/androidx/releases/core#1.19.1)

```
@RequiresApi(value = 37)
java-static fun forPausedTimer(remainingTime: Duration, format: Int): NotificationCompat.Metric.TimeDifference
```

Creates a "paused timer" metric, showing the `remainingTime`.

### forStopwatch

Added in [1.19.1](https://developer.android.com/jetpack/androidx/releases/core#1.19.1)

```
@RequiresApi(value = 37)
java-static fun forStopwatch(startTime: Instant, format: Int): NotificationCompat.Metric.TimeDifference
```

Creates a "running stopwatch" metric, which will show the time elapsed since `startTime`.

| Parameters |
|---|---|
| `startTime: https://developer.android.com/reference/java/time/Instant.html` | instant at which the stopwatch started |
| `format: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | formatting option |

### forStopwatch

Added in [1.19.1](https://developer.android.com/jetpack/androidx/releases/core#1.19.1)

```
@RequiresApi(value = 37)
java-static fun forStopwatch(startTime: Long, format: Int): NotificationCompat.Metric.TimeDifference
```

Creates a "running stopwatch" metric, which will show the time elapsed since `startTime`, specified in the `https://developer.android.com/reference/android/os/SystemClock.html#elapsedRealtime()` frame of reference.

| Parameters |
|---|---|
| `startTime: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | elapsed realtime at which the stopwatch started |
| `format: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | formatting option |

### forTimer

Added in [1.19.1](https://developer.android.com/jetpack/androidx/releases/core#1.19.1)

```
@RequiresApi(value = 37)
java-static fun forTimer(endTime: Instant, format: Int): NotificationCompat.Metric.TimeDifference
```

Creates a "running timer" metric, which will show a countdown to `endTime`.

| Parameters |
|---|---|
| `endTime: https://developer.android.com/reference/java/time/Instant.html` | instant at which the timer reaches zero |
| `format: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | formatting option |

### forTimer

Added in [1.19.1](https://developer.android.com/jetpack/androidx/releases/core#1.19.1)

```
@RequiresApi(value = 37)
java-static fun forTimer(endTime: Long, format: Int): NotificationCompat.Metric.TimeDifference
```

Creates a "running timer" metric, which will show a countdown to `endTime`, specified in the `https://developer.android.com/reference/android/os/SystemClock.html#elapsedRealtime()` frame of reference.

| Parameters |
|---|---|
| `endTime: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | elapsed realtime at which the timer reaches zero |
| `format: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | formatting option |

### getFormat

Added in [1.19.1](https://developer.android.com/jetpack/androidx/releases/core#1.19.1)

```
fun getFormat(): Int
```

Formatting option for the timer/stopwatch.

### getPausedDuration

Added in [1.19.1](https://developer.android.com/jetpack/androidx/releases/core#1.19.1)

```
fun getPausedDuration(): Duration?
```

The fixed time difference, for a paused timer or stopwatch.

- For a paused timer this is the `remainingTime` supplied to `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Metric.TimeDifference#forPausedTimer(java.time.Duration,int)`.
- For a paused stopwatch this is the `elapsedTime` supplied to `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Metric.TimeDifference#forPausedStopwatch(java.time.Duration,int)`.
- For running timers or stopwatches this is `null`.

### getZeroElapsedRealtime

Added in [1.19.1](https://developer.android.com/jetpack/androidx/releases/core#1.19.1)

```
fun getZeroElapsedRealtime(): Long?
```

The elapsed realtime at which the time difference is zero. Only valid for an `https://developer.android.com/reference/android/os/SystemClock.html#elapsedRealtime()`-based `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Metric.TimeDifference`.

- For a running timer this is the `endTime` supplied to `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Metric.TimeDifference#forTimer(long,int)`.
- For a running stopwatch this is the `startTime` supplied to `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Metric.TimeDifference#forStopwatch(long,int)`.
- For running timers or stopwatches based on `https://developer.android.com/reference/java/time/Instant.html` (as well as paused timers and stopwatches), this is `null`.

### getZeroTime

Added in [1.19.1](https://developer.android.com/jetpack/androidx/releases/core#1.19.1)

```
fun getZeroTime(): Instant?
```

The `https://developer.android.com/reference/java/time/Instant.html` at which the time difference is zero. Only valid for an `https://developer.android.com/reference/java/time/Instant.html`-based `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Metric.TimeDifference`.

- For a running timer this is the `endTime` supplied to `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Metric.TimeDifference#forTimer(java.time.Instant,int)`.
- For a running stopwatch this is the `startTime` supplied to `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Metric.TimeDifference#forStopwatch(java.time.Instant,int)`.
- For running timers or stopwatches based on elapsed realtime (as well as paused timers and stopwatches), this is `null`.

### hashCode

```
fun hashCode(): Int
```

### isStopwatch

Added in [1.19.1](https://developer.android.com/jetpack/androidx/releases/core#1.19.1)

```
fun isStopwatch(): Boolean
```

Whether this `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Metric.TimeDifference` value represents a stopwatch -- when running, it counts up from `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Metric.TimeDifference#getZeroTime()` (or `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Metric.TimeDifference#getZeroElapsedRealtime()`).

### isTimer

Added in [1.19.1](https://developer.android.com/jetpack/androidx/releases/core#1.19.1)

```
fun isTimer(): Boolean
```

Whether this `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Metric.TimeDifference` value represents a timer -- when running, it counts down to `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Metric.TimeDifference#getZeroTime()` (or `https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Metric.TimeDifference#getZeroElapsedRealtime()`).

### toString

```
fun toString(): String
```