DateTimeWithZone

public final class DateTimeWithZone
extends Object

java.lang.Object
   ↳ androidx.car.app.model.DateTimeWithZone


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 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(long, TimeZone) and create(ZonedDateTime) are provided for convenience if using java.util and java.time respectively. If using another library such as Joda time, create(long, int, String) can be used.

Summary

Public methods

static DateTimeWithZone create(long timeSinceEpochMillis, TimeZone timeZone)

Returns an instance of a DateTimeWithZone.

static DateTimeWithZone create(ZonedDateTime zonedDateTime)

Returns an instance of a DateTimeWithZone.

static DateTimeWithZone create(long timeSinceEpochMillis, int zoneOffsetSeconds, String zoneShortName)

Returns an instance of a DateTimeWithZone.

boolean equals(Object other)
long getTimeSinceEpochMillis()

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

int getZoneOffsetSeconds()

Returns the offset of the time zone from UTC.

String getZoneShortName()

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

int hashCode()
String toString()

Inherited methods

Public methods

create

public static DateTimeWithZone create (long timeSinceEpochMillis, 
                TimeZone timeZone)

Returns an instance of a DateTimeWithZone.

Parameters
timeSinceEpochMillis long: The number of milliseconds from the epoch of 1970-01-01T00:00:00Z

timeZone TimeZone: 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

Returns
DateTimeWithZone

Throws
IllegalArgumentException if timeSinceEpochMillis is a negative value
NullPointerException if timeZone is null

create

public static DateTimeWithZone create (ZonedDateTime zonedDateTime)

Returns an instance of a DateTimeWithZone.

Parameters
zonedDateTime ZonedDateTime: 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

Returns
DateTimeWithZone

Throws
NullPointerException if zonedDateTime is null

create

public static DateTimeWithZone create (long timeSinceEpochMillis, 
                int zoneOffsetSeconds, 
                String zoneShortName)

Returns an instance of a DateTimeWithZone.

Parameters
timeSinceEpochMillis long: The number of milliseconds from the epoch of 1970-01-01T00:00:00Z

zoneOffsetSeconds int: 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

Value is between -64800 and 64800 inclusive.

zoneShortName String: 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

Returns
DateTimeWithZone

Throws
IllegalArgumentException if timeSinceEpochMillis is a negative value, if zoneOffsetSeconds is not within the required range, or if zoneShortName is empty
NullPointerException if zoneShortName is null

equals

public boolean equals (Object other)

Parameters
other Object

Returns
boolean

getTimeSinceEpochMillis

public long getTimeSinceEpochMillis ()

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

Returns
long

getZoneOffsetSeconds

public int getZoneOffsetSeconds ()

Returns the offset of the time zone from UTC.

Returns
int

getZoneShortName

public String getZoneShortName ()

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

Returns
String

hashCode

public int hashCode ()

Returns
int

toString

public String toString ()

Returns
String