DateTimeWithZone
@CarProtocol
public final class 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 and create are provided for convenience if using java.util and java.time respectively. If using another library such as Joda time, create can be used.
Summary
Public methods |
|
|---|---|
static @NonNull DateTimeWithZone |
@RequiresApi(value = 26)Returns an instance of a |
static @NonNull DateTimeWithZone |
Returns an instance of a |
static @NonNull DateTimeWithZone |
create(Returns an instance of a |
boolean |
|
long |
Returns the number of milliseconds from the epoch of 1970-01-01T00:00:00Z. |
int |
Returns the offset of the time zone from UTC. |
@Nullable String |
Returns the abbreviated name of the time zone, for example "PST" for Pacific Standard Time. |
int |
hashCode() |
@NonNull String |
toString() |
Public methods
create
@RequiresApi(value = 26)
public static @NonNull DateTimeWithZone create(@NonNull ZonedDateTime zonedDateTime)
Returns an instance of a DateTimeWithZone.
| Parameters | |
|---|---|
@NonNull 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 |
| Throws | |
|---|---|
java.lang.NullPointerException |
if |
create
public static @NonNull DateTimeWithZone create(long timeSinceEpochMillis, @NonNull TimeZone timeZone)
Returns an instance of a DateTimeWithZone.
| Parameters | |
|---|---|
long timeSinceEpochMillis |
The number of milliseconds from the epoch of 1970-01-01T00:00:00Z |
@NonNull TimeZone timeZone |
The time zone at the date specified by |
| Throws | |
|---|---|
java.lang.IllegalArgumentException |
if |
java.lang.NullPointerException |
if |
create
public static @NonNull DateTimeWithZone create(
long timeSinceEpochMillis,
@IntRange(from = "-64800", to = 64800) int zoneOffsetSeconds,
@NonNull String zoneShortName
)
Returns an instance of a DateTimeWithZone.
| Parameters | |
|---|---|
long timeSinceEpochMillis |
The number of milliseconds from the epoch of 1970-01-01T00:00:00Z |
@IntRange(from = "-64800", to = 64800) int zoneOffsetSeconds |
The offset of the time zone from UTC at the date specified by |
@NonNull String zoneShortName |
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 |
if |
java.lang.NullPointerException |
if |
getTimeSinceEpochMillis
public long getTimeSinceEpochMillis()
Returns the number of milliseconds from the epoch of 1970-01-01T00:00:00Z.
getZoneOffsetSeconds
public int getZoneOffsetSeconds()
Returns the offset of the time zone from UTC.
getZoneShortName
public @Nullable String getZoneShortName()
Returns the abbreviated name of the time zone, for example "PST" for Pacific Standard Time.