public final class ZonalDateTime extends Object implements ChronoDisplay, UniversalTime, ThreetenAdapter
Combination of UTC-moment and timezone.
An instance can be created by Moment.inLocalView() or
Moment.inZonalView(...). This type mainly serves for various
type conversions and incorporates a valid local timestamp as well as an
universal time in UTC. If users wish to apply any kind of data
manipulation then an object of this type has first to be converted
to a local timestamp or to a global UTC-moment. Example:
Moment moment = ...; ZonalDateTime zdt = moment.inLocalView(); // manipulation on local timeline PlainTimestamp localTSP = zdt.toTimestamp().plus(30, ClockUnit.SECONDS); // manipulation on global timeline Moment globalTSP = zdt.toMoment().plus(30, SI.SECONDS);
This class supports all elements which are supported by Moment
and PlainTimestamp, too.
Moment.inLocalView(),
Moment.inZonalView(TZID),
Moment.inZonalView(String)| Modifier and Type | Method and Description |
|---|---|
boolean |
contains(ChronoElement<?> element)
Queries if the value for given chronological element can be
accessed via
get(element). |
boolean |
equals(Object obj) |
static ZonalDateTime |
from(ZonedDateTime zdt)
Short cut for
TemporalType.ZONED_DATE_TIME.translate(zdt). |
<V> V |
get(ChronoElement<V> element)
Returns the partial value associated with given chronological
element.
|
long |
getElapsedTime(TimeScale scale)
Represents this timestamp as elpased seconds on given time scale.
|
<V> V |
getMaximum(ChronoElement<V> element)
Yields the maximum value of given chronological element in the
current context of this object.
|
<V> V |
getMinimum(ChronoElement<V> element)
Yields the minimum value of given chronological element in the
current context of this object.
|
int |
getNanosecond()
Yields the nanosecond fraction of current second.
|
int |
getNanosecond(TimeScale scale)
Represents the nanosecond part on the given time scale.
|
ZonalOffset |
getOffset()
Yields the timezone offset.
|
long |
getPosixTime()
Counts the seconds elapsed since UNIX epoch
[1970-01-01T00:00:00Z] in UTC timezone.
|
TZID |
getTimezone()
Returns the associated timezone ID for display purposes
if available.
|
int |
hashCode() |
boolean |
hasTimezone()
This object always has a timezone.
|
boolean |
isLeapSecond()
Queries if this time point is within a positive leapsecond.
|
static ZonalDateTime |
parse(String text,
TemporalFormatter<Moment> parser)
Parses given text to a
ZonalDateTime. |
String |
print(TemporalFormatter<Moment> printer)
Creates a formatted output of this instance.
|
static ZonalDateTime |
read(ObjectInput input)
This is the reverse operation of
write(ObjectOutput). |
Moment |
toMoment()
Converts this object to a global UTC-moment.
|
String |
toString()
Yields a canonical representation in ISO-like-style.
|
ZonedDateTime |
toTemporalAccessor()
Converts this object to a
TemporalAccessor. |
PlainTimestamp |
toTimestamp()
Converts this object to a zonal timestamp.
|
void |
write(ObjectOutput output)
Writes this instance to given output (serialization).
|
get, getLong, isSupported, query, rangepublic boolean contains(ChronoElement<?> element)
ChronoDisplayQueries if the value for given chronological element can be
accessed via get(element).
If the argument is missing then this method will yield false.
Note: Elements which are not registered but define a suitable rule
are also accessible.
contains in interface ChronoDisplayelement - chronological element to be asked (optional)true if the method get(ChronoElement) can
be called without exception else falseChronoDisplay.get(ChronoElement)public <V> V get(ChronoElement<V> element)
ChronoDisplayReturns the partial value associated with given chronological element.
get in interface ChronoDisplayV - generic type of element valueelement - element which has the valuenull)ChronoDisplay.contains(ChronoElement)public <V> V getMinimum(ChronoElement<V> element)
ChronoDisplayYields the minimum value of given chronological element in the current context of this object.
The definition of a minimum and a maximum does generally not imply that every intermediate value between minimum and maximum is valid in this context. For example in the timezone Europe/Berlin the hour [T02:00] will be invalid if switching to summer time.
In most cases the minimum value is not dependent on this context.
getMinimum in interface ChronoDisplayV - generic type of element valueelement - element whose minimum value is to be evaluatedChronoElement.getDefaultMinimum(),
ChronoDisplay.getMaximum(ChronoElement)public <V> V getMaximum(ChronoElement<V> element)
ChronoDisplayYields the maximum value of given chronological element in the current context of this object.
Maximum values are different from minimum case often dependent
on the context. An example is the element SECOND_OF_MINUTE whose
maximum is normally 59 but can differ in UTC-context with
leap seconds. Another more common example is the maximum of the
element DAY_OF_MONTH (28-31) which is dependent on the month and year
of this context (leap years!).
Note: In timezone-related timestamps possible offset jumps inducing gaps on the local timeline will be conserved. That means that minimum and maximum do not guarantee a continuum of valid intermediate values.
getMaximum in interface ChronoDisplayV - generic type of element valueelement - element whose maximum value is to be evaluatedChronoElement.getDefaultMaximum(),
ChronoDisplay.getMinimum(ChronoElement)public boolean hasTimezone()
This object always has a timezone.
hasTimezone in interface ChronoDisplaytruepublic TZID getTimezone()
ChronoDisplayReturns the associated timezone ID for display purposes if available.
Note: Although global types like Moment indeed have a
timezone reference (namely UTC+00:00), such types will not support
formatted output without explicitly giving a timezone for display
purposes. Therefore calling this method on global types will throw
an exception. This method is not just about any timezone reference
but a timezone designed for display purposes.
getTimezone in interface ChronoDisplayChronoDisplay.hasTimezone()public ZonalOffset getOffset()
Yields the timezone offset.
public Moment toMoment()
Converts this object to a global UTC-moment.
public PlainTimestamp toTimestamp()
Converts this object to a zonal timestamp.
public static ZonalDateTime from(ZonedDateTime zdt)
Short cut for TemporalType.ZONED_DATE_TIME.translate(zdt).
zdt - Threeten-equivalent of a zonal date-timeTemporalType.ZONED_DATE_TIMEpublic long getElapsedTime(TimeScale scale)
UniversalTimeRepresents this timestamp as elpased seconds on given time scale.
The method getPosixTime() inherited from UnixTime
is equivalent to getElapsedTime(TimeScale.POSIX) and relates
to the UNIX-epoch 1970-01-01. The time scale UTC starts two years
later however and also counts leapseconds.
getElapsedTime in interface UniversalTimescale - time scale referencepublic int getNanosecond(TimeScale scale)
UniversalTimeRepresents the nanosecond part on the given time scale.
The method with the same name and without argument inherited from
super interface UnixTime is identical to this method if the
time scale is either POSIX or UTC.
getNanosecond in interface UniversalTimescale - time scale referencepublic boolean isLeapSecond()
UniversalTimeQueries if this time point is within a positive leapsecond.
If the support for UTC-leapseconds is switched off per configuration
then this method will always yield false.
isLeapSecond in interface UniversalTimetrue if this instance represents a positive
leap second else falseLeapSeconds.isEnabled()public long getPosixTime()
UnixTimeCounts the seconds elapsed since UNIX epoch [1970-01-01T00:00:00Z] in UTC timezone.
getPosixTime in interface UnixTimepublic int getNanosecond()
UnixTimeYields the nanosecond fraction of current second.
As time unit, the nanosecond is defined as one billionth part of a second).
getNanosecond in interface UnixTime0 - 999.999.999public String print(TemporalFormatter<Moment> printer)
Creates a formatted output of this instance.
printer - helps to format this instancepublic static ZonalDateTime parse(String text, TemporalFormatter<Moment> parser) throws ParseException
Parses given text to a ZonalDateTime.
text - text to be parsedparser - helps to parse given textIndexOutOfBoundsException - if the text is emptyParseException - if the text is not parseablepublic String toString()
Yields a canonical representation in ISO-like-style.
public ZonedDateTime toTemporalAccessor()
ThreetenAdapterConverts this object to a TemporalAccessor.
Any implementation is required to return a new object with a different concrete type, not this instance.
toTemporalAccessor in interface ThreetenAdapterpublic void write(ObjectOutput output) throws IOException
Writes this instance to given output (serialization).
Warning: Serializing this instance is a heavy-weight-operation because the whole relevant timezone data will be written to given stream, not only the timezone-id.
output - object outputIOException - if writing failspublic static ZonalDateTime read(ObjectInput input) throws IOException, ClassNotFoundException
This is the reverse operation of write(ObjectOutput).
input - object inputZonalDateTimeIOException - if reading failsClassNotFoundException - if class-loading failsIllegalArgumentException - in case of inconsistent dataCopyright © 2014–2015. All rights reserved.