# DateTimeWithZone

# DateTimeWithZone

Artifact:[androidx.car.app:app](https://developer.android.com/jetpack/androidx/releases/car-app)  
[View Source](https://cs.android.com/search?q=file:androidx/car/app/model/DateTimeWithZone.java+class:androidx.car.app.model.DateTimeWithZone)  
Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/car/app/model/DateTimeWithZone "View this page in Java")

<br />

```
@CarProtocol
class DateTimeWithZone
```

<br />

*** ** * ** ***

A time with an associated time zone information.

In order to avoid time zone databases being out of sync between the app and the host, this model avoids using[IANA database](https://www.iana.org/time-zones)time zone IDs and instead relies on the app passing the time zone offset and its abbreviated name. Apps can use their time library of choice to retrieve the time zone information.

[create](https://developer.android.com/reference/kotlin/androidx/car/app/model/DateTimeWithZone#create(long,java.util.TimeZone))and[create](https://developer.android.com/reference/kotlin/androidx/car/app/model/DateTimeWithZone#create(java.time.ZonedDateTime))are provided for convenience if using`java.util`and`java.time`respectively. If using another library such as Joda time,[create](https://developer.android.com/reference/kotlin/androidx/car/app/model/DateTimeWithZone#create(long,int,java.lang.String))can be used.

## Summary

|                                                   ### Public functions                                                   |
|--------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `java-static `[DateTimeWithZone](https://developer.android.com/reference/kotlin/androidx/car/app/model/DateTimeWithZone) | `@`[RequiresApi](https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi)`(value = 26)` [create](https://developer.android.com/reference/kotlin/androidx/car/app/model/DateTimeWithZone#create(java.time.ZonedDateTime))`(zonedDateTime: `[ZonedDateTime](https://developer.android.com/reference/java/time/ZonedDateTime.html)`)` Returns an instance of a[DateTimeWithZone](https://developer.android.com/reference/kotlin/androidx/car/app/model/DateTimeWithZone).                                                                                                                                                                                                                            |
| `java-static `[DateTimeWithZone](https://developer.android.com/reference/kotlin/androidx/car/app/model/DateTimeWithZone) | [create](https://developer.android.com/reference/kotlin/androidx/car/app/model/DateTimeWithZone#create(long,java.util.TimeZone))`(timeSinceEpochMillis: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)`, timeZone: `[TimeZone](https://developer.android.com/reference/java/util/TimeZone.html)`)` Returns an instance of a[DateTimeWithZone](https://developer.android.com/reference/kotlin/androidx/car/app/model/DateTimeWithZone).                                                                                                                                                                                                                                                   |
| `java-static `[DateTimeWithZone](https://developer.android.com/reference/kotlin/androidx/car/app/model/DateTimeWithZone) | [create](https://developer.android.com/reference/kotlin/androidx/car/app/model/DateTimeWithZone#create(long,int,java.lang.String))`(` ` timeSinceEpochMillis: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)`,` ` zoneOffsetSeconds: @`[IntRange](https://developer.android.com/reference/kotlin/androidx/annotation/IntRange)`(from = "-64800", to = 64800) `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`,` ` zoneShortName: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html) `)` Returns an instance of a[DateTimeWithZone](https://developer.android.com/reference/kotlin/androidx/car/app/model/DateTimeWithZone). |
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)                                      | [equals](https://developer.android.com/reference/kotlin/androidx/car/app/model/DateTimeWithZone#equals(java.lang.Object))`(other: `[Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)`?)`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| [Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)                                            | [getTimeSinceEpochMillis](https://developer.android.com/reference/kotlin/androidx/car/app/model/DateTimeWithZone#getTimeSinceEpochMillis())`()` Returns the number of milliseconds from the epoch of 1970-01-01T00:00:00Z.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                              | [getZoneOffsetSeconds](https://developer.android.com/reference/kotlin/androidx/car/app/model/DateTimeWithZone#getZoneOffsetSeconds())`()` Returns the offset of the time zone from UTC.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`?`                                     | [getZoneShortName](https://developer.android.com/reference/kotlin/androidx/car/app/model/DateTimeWithZone#getZoneShortName())`()` Returns the abbreviated name of the time zone, for example "PST" for Pacific Standard Time.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                              | [hashCode](https://developer.android.com/reference/kotlin/androidx/car/app/model/DateTimeWithZone#hashCode())`()`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)                                        | [toString](https://developer.android.com/reference/kotlin/androidx/car/app/model/DateTimeWithZone#toString())`()`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |

## Public functions

### create

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

```
@RequiresApi(value = 26)
java-static fun create(zonedDateTime: ZonedDateTime): DateTimeWithZone
```

Returns an instance of a[DateTimeWithZone](https://developer.android.com/reference/kotlin/androidx/car/app/model/DateTimeWithZone).  

|                                               Parameters                                               |
|--------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `zonedDateTime: `[ZonedDateTime](https://developer.android.com/reference/java/time/ZonedDateTime.html) | The time with a time zone. The abbreviated name of this time zone, formatted using the default locale, may be displayed to the user when needed, for example, if this time zone is different than the current system time zone |

|                                                    Throws                                                     |
|---------------------------------------------------------------------------------------------------------------|---------------------------|
| [java.lang.NullPointerException](https://developer.android.com/reference/java/lang/NullPointerException.html) | if`zonedDateTime`is`null` |

### create

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

```
java-static fun create(timeSinceEpochMillis: Long, timeZone: TimeZone): DateTimeWithZone
```

Returns an instance of a[DateTimeWithZone](https://developer.android.com/reference/kotlin/androidx/car/app/model/DateTimeWithZone).  

|                                              Parameters                                               |
|-------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `timeSinceEpochMillis: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html) | The number of milliseconds from the epoch of 1970-01-01T00:00:00Z                                                                                                                                                                                            |
| `timeZone: `[TimeZone](https://developer.android.com/reference/java/util/TimeZone.html)               | The time zone at the date specified by`timeInUtcMillis`. The abbreviated name of this time zone, formatted using the default locale, may be displayed to the user when needed, for example, if this time zone is different than the current system time zone |

|                                                        Throws                                                         |
|-----------------------------------------------------------------------------------------------------------------------|---------------------------------------------|
| [java.lang.IllegalArgumentException](https://developer.android.com/reference/java/lang/IllegalArgumentException.html) | if`timeSinceEpochMillis`is a negative value |
| [java.lang.NullPointerException](https://developer.android.com/reference/java/lang/NullPointerException.html)         | if`timeZone`is`null`                        |

### create

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

```
java-static fun create(
    timeSinceEpochMillis: Long,
    zoneOffsetSeconds: @IntRange(from = "-64800", to = 64800) Int,
    zoneShortName: String
): DateTimeWithZone
```

Returns an instance of a[DateTimeWithZone](https://developer.android.com/reference/kotlin/androidx/car/app/model/DateTimeWithZone).  

|                                                                                                        Parameters                                                                                                        |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `timeSinceEpochMillis: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)                                                                                                                    | The number of milliseconds from the epoch of 1970-01-01T00:00:00Z                                                                                                                                                                                  |
| `zoneOffsetSeconds: @`[IntRange](https://developer.android.com/reference/kotlin/androidx/annotation/IntRange)`(from = "-64800", to = 64800) `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | The offset of the time zone from UTC at the date specified by`timeInUtcMillis`. This offset must be in the range`-18:00`to`+18:00`, which corresponds to -64800 to +64800                                                                          |
| `zoneShortName: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)                                                                                                                       | The abbreviated name of the time zone, for example, "PST" for Pacific Standard Time. This string may be used to display to the user along with the date when needed, for example, if this time zone is different than the current system time zone |

|                                                        Throws                                                         |
|-----------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------|
| [java.lang.IllegalArgumentException](https://developer.android.com/reference/java/lang/IllegalArgumentException.html) | if`timeSinceEpochMillis`is a negative value, if`zoneOffsetSeconds`is not within the required range, or if`zoneShortName`is empty |
| [java.lang.NullPointerException](https://developer.android.com/reference/java/lang/NullPointerException.html)         | if`zoneShortName`is`null`                                                                                                        |

### equals

```
fun equals(other: Any?): Boolean
```  

### getTimeSinceEpochMillis

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

```
fun getTimeSinceEpochMillis(): Long
```

Returns the number of milliseconds from the epoch of 1970-01-01T00:00:00Z.  

### getZoneOffsetSeconds

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

```
fun getZoneOffsetSeconds(): Int
```

Returns the offset of the time zone from UTC.  

### getZoneShortName

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

```
fun getZoneShortName(): String?
```

Returns the abbreviated name of the time zone, for example "PST" for Pacific Standard Time.  

### hashCode

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

### toString

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