Class PlainTime
- All Implemented Interfaces:
Serializable
,Comparable<PlainTime>
,TemporalAccessor
,WallTime
,ChronoDisplay
,Temporal<PlainTime>
,ThreetenAdapter
,LocalizedPatternSupport
Represents a plain wall time without any timezone or date component as defined in ISO-8601 up to nanosecond precision.
This type also supports the special value 24:00 in its state space. That value means midnight at the end of day and can be both set and queried.
Following elements which are declared as constants are registered by this class:
COMPONENT
AM_PM_OF_DAY
CLOCK_HOUR_OF_AMPM
CLOCK_HOUR_OF_DAY
DIGITAL_HOUR_OF_AMPM
DIGITAL_HOUR_OF_DAY
HOUR_FROM_0_TO_24
MINUTE_OF_HOUR
MINUTE_OF_DAY
SECOND_OF_MINUTE
SECOND_OF_DAY
MILLI_OF_SECOND
MICRO_OF_SECOND
NANO_OF_SECOND
MILLI_OF_DAY
MICRO_OF_DAY
NANO_OF_DAY
PRECISION
DECIMAL_HOUR
DECIMAL_MINUTE
DECIMAL_SECOND
- Author:
- Meno Hochschild
- See Also:
- Serialized Form
-
Field Summary
Modifier and TypeFieldDescriptionstatic ZonalElement<Meridiem>
Element with the half day section relative to noon (ante meridiem or post meridiem).static AdjustableElement<Integer,PlainTime>
Element with the hour of half day in the value range1-12
(dial on an analogue watch).static AdjustableElement<Integer,PlainTime>
Element with the hour in the value range1-24
(analogue display).static WallTimeElement
Element with the wall time in the value range[T00:00:00,000000000]
until[T24:00:00,000000000]
(inclusive in the context ofPlainTime
else exclusive).static ZonalElement<BigDecimal>
Decimal hour in the value range0.0
inclusive until24.0
exclusive (inclusive inPlainTime
).static ZonalElement<BigDecimal>
Decimal minute in the value range0.0
inclusive until60.0
exclusive.static ZonalElement<BigDecimal>
Decimal second in the value range0.0
inclusive until60.0
exclusive.static ProportionalElement<Integer,PlainTime>
Element with the digital hour of half day in the value range0-11
.static ProportionalElement<Integer,PlainTime>
Element with the digital hour in the value range0-23
.static ProportionalElement<Integer,PlainTime>
Element with the full hour of day in the value range0-24
.static ProportionalElement<Long,PlainTime>
Element with the day time in microseconds in the value range0-86400000000
.static ProportionalElement<Integer,PlainTime>
Element with the microsecond in the value range0-999999
.static ProportionalElement<Integer,PlainTime>
Element with the day time in milliseconds in the value range0-86400000
.static ProportionalElement<Integer,PlainTime>
Element with the millisecond in the value range0-999
.static ProportionalElement<Integer,PlainTime>
Element with the minute of day in the value range0-1440
.static ProportionalElement<Integer,PlainTime>
Element with the minute of hour in the value range0-59
.static ProportionalElement<Long,PlainTime>
Element with the day time in nanoseconds in the value range0-86400000000000
.static ProportionalElement<Integer,PlainTime>
Element with the nanosecond in the value range0-999999999
.static ChronoElement<ClockUnit>
Defines the precision as the smallest non-zero time element and truncates time parts of higher precision if necessary.static ProportionalElement<Integer,PlainTime>
Element with the second of day in the value range0-86400
.static ProportionalElement<Integer,PlainTime>
Element with the second of minute in the value range0-59
. -
Method Summary
Modifier and TypeMethodDescriptionstatic TimeAxis<IsoTimeUnit,PlainTime>
axis()
Provides a static access to the associated time axis respective chronology which contains the chronological rules.int
Defines a natural order which is solely based on the timeline order.boolean
Compares the full state, that is hour, minute, second and nanosecond of this instance and given argument.static PlainTime
Short cut forTemporalType.LOCAL_TIME.translate(time)
.static PlainTime
Common conversion method.getFormatPattern(FormatStyle style, Locale locale)
Defines a CLDR-compatible localized format pattern suitable for printing.int
getHour()
Yields the hour of day.int
Yields the minute of hour.int
Yields the nanosecond.int
Yields the second of minute.int
hashCode()
Subclasses must redefine this method corresponding to the behaviour ofequals()
.boolean
Queries if this object is after given object on a timeline.boolean
Queries if this object is before given object on a timeline.boolean
Is this instance at midnight, either at start or at end of day?boolean
isSimultaneous(PlainTime time)
Queries if this object and given object have the same position on the time axis.static PlainTime
Yields midnight at the end of the day, that is midnight at the start of the following day.static PlainTime
Yields midnight at the start of the day.Subtracts given amount in units from this clock time and yields the result of subtraction.static PlainTime
Obtains the current clock time in system time.static PlainTime
of(int hour)
Creates a wall time as full hour.static PlainTime
of(int hour, int minute)
Creates a wall time with hour and minute.static PlainTime
of(int hour, int minute, int second)
Creates a wall time with hour, minute and second.static PlainTime
of(int hour, int minute, int second, int nanosecond)
Creates a wall time with hour, minute, second and nanosecond.static PlainTime
of(BigDecimal decimal)
Creates a wall time by given decimal hour.static PlainTime
parse(String text, TemporalFormatter<PlainTime> parser)
Parses given text to an instance of this class.Adds given amount in units to this clock time and yields the result of addition.print(TemporalFormatter<PlainTime> printer)
Creates a formatted output of this instance.Rolls this time by the given duration (as amount and unit) and also counts possible day overflow.static Chronology<LocalTime>
threeten()
Obtains a bridge chronology for the typejava.time.LocalTime
.toString()
Dependent on the precision of this instance, this method yields a canonical representation in one of following formats (CLDR-syntax):Converts this object to aTemporalAccessor
.Methods inherited from class net.time4j.engine.TimePoint
max, min, minus, minus, plus, plus, until, until
Methods inherited from class net.time4j.engine.ChronoEntity
contains, get, get, getInt, getMaximum, getMinimum, getRegisteredElements, getTimezone, hasTimezone, isValid, isValid, isValid, matches, with, with, with, with
Methods inherited from interface net.time4j.format.LocalizedPatternSupport
getFormatPattern, useDynamicFormatPattern
Methods inherited from interface net.time4j.engine.Temporal
isAfterAll, isAfterOrEqual, isBeforeAll, isBeforeOrEqual
Methods inherited from interface net.time4j.engine.ThreetenAdapter
get, getLong, isSupported, query, range
-
Field Details
-
COMPONENT
Element with the wall time in the value range
[T00:00:00,000000000]
until[T24:00:00,000000000]
(inclusive in the context ofPlainTime
else exclusive).Example of usage:
PlainTimestamp tsp = ChronoFormatter.ofTimestampPattern("uuuu-MM-dd", PatternType.CLDR, Locale.getDefault()) .withDefault( PlainTime.COMPONENT, PlainTime.midnightAtStartOfDay()) .parse("2014-08-20"); System.out.println(tsp); // output: 2014-08-20T00
Note: This element does not define any base unit.
- Since:
- 1.2
-
AM_PM_OF_DAY
Element with the half day section relative to noon (ante meridiem or post meridiem).
This element handles the value 24:00 in the same way as 00:00, hence does not make any difference between start and end of day. In detail the mapping from hours to meridiem values looks like following:
Legend AM_PM_OF_DAY AM AM ... AM PM PM ... PM AM ISO-8601-Wert T0 T1 ... T11 T12 T13 ... T23 T24 Example:
import static net.time4j.PlainTime.AM_PM_OF_DAY; PlainTime time = PlainTime.of(12, 45, 20); System.out.println(time.get(AM_PM_OF_DAY)); // Output: PM
This element does not define a base unit.
-
CLOCK_HOUR_OF_AMPM
@FormattableElement(format="h") public static final AdjustableElement<Integer,PlainTime> CLOCK_HOUR_OF_AMPMElement with the hour of half day in the value range
1-12
(dial on an analogue watch).This element handles the value 24:00 in the same way as 00:00, hence does not make any difference between start and end of day. This is a limitation which preserves the compatibility with CLDR and the class
java.text.SimpleDateFormat
. In order to support the full hour range users can use the elementHOUR_FROM_0_TO_24
. In detail the mapping to full hours in range 0-24 looks like following:Legend CLOCK_HOUR_OF_AMPM 12 1 ... 11 12 1 ... 11 12 Full-range hour T0 T1 ... T11 T12 T13 ... T23 T24 -
CLOCK_HOUR_OF_DAY
@FormattableElement(format="k") public static final AdjustableElement<Integer,PlainTime> CLOCK_HOUR_OF_DAYElement with the hour in the value range
1-24
(analogue display).This element handles the value 24:00 in the same way as 00:00, hence does not make any difference between start and end of day. This is a limitation which preserves the compatibility with CLDR and the class
java.text.SimpleDateFormat
. In order to support the full hour range users can use the elementHOUR_FROM_0_TO_24
. In detail the mapping to full hours in range 0-24 looks like following:Legend CLOCK_HOUR_OF_DAY 24 1 ... 11 12 13 ... 23 24 Full-range hour T0 T1 ... T11 T12 T13 ... T23 T24 -
DIGITAL_HOUR_OF_AMPM
@FormattableElement(format="K") public static final ProportionalElement<Integer,PlainTime> DIGITAL_HOUR_OF_AMPMElement with the digital hour of half day in the value range
0-11
.This element handles the value 24:00 in the same way as 00:00, hence does not make any difference between start and end of day. This is a limitation which preserves the compatibility with CLDR and the class
java.text.SimpleDateFormat
. In order to support the full hour range users can use the elementHOUR_FROM_0_TO_24
. In detail the mapping to full hours in range 0-24 looks like following:Legend DIGITAL_HOUR_OF_AMPM 0 1 ... 11 0 1 ... 11 0 Full-range hour T0 T1 ... T11 T12 T13 ... T23 T24 -
DIGITAL_HOUR_OF_DAY
@FormattableElement(format="H") public static final ProportionalElement<Integer,PlainTime> DIGITAL_HOUR_OF_DAYElement with the digital hour in the value range
0-23
.This element handles the value 24:00 in the same way as 00:00, hence does not make any difference between start and end of day. This is a limitation which preserves the compatibility with CLDR and the class
java.text.SimpleDateFormat
. In order to support the full hour range users can use the elementHOUR_FROM_0_TO_24
. In detail the mapping to full hours in range 0-24 looks like following:Legend DIGITAL_HOUR_OF_DAY 0 1 ... 11 12 13 ... 23 0 Full-range hour T0 T1 ... T11 T12 T13 ... T23 T24 -
HOUR_FROM_0_TO_24
Element with the full hour of day in the value range
0-24
.Given a context of
PlainTime
with full hours, the maximum is24
and stands for the time 24:00 (midnight at end of day), else the maximum is23
in every different context.- Since:
- v3.35/4.30
- See Also:
getHour()
-
MINUTE_OF_HOUR
@FormattableElement(format="m") public static final ProportionalElement<Integer,PlainTime> MINUTE_OF_HOURElement with the minute of hour in the value range
0-59
.- See Also:
getMinute()
-
MINUTE_OF_DAY
Element with the minute of day in the value range
0-1440
.Given a context of
PlainTime
with full minutes, the maximum is1440
and stands for the time 24:00 (midnight at end of day), else the maximum is1439
in every different context. -
SECOND_OF_MINUTE
@FormattableElement(format="s") public static final ProportionalElement<Integer,PlainTime> SECOND_OF_MINUTEElement with the second of minute in the value range
0-59
.This element does not know any leapseconds in a local context and refers to a normal analogue clock. If this element is used in UTC-context (
Moment
) however then the value range is0-58/59/60
instead.- See Also:
getSecond()
-
SECOND_OF_DAY
Element with the second of day in the value range
0-86400
.Given a context of
PlainTime
with full seconds, the maximum is86400
and stands for the time 24:00 (midnight at end of day), else the maximum is86399
in every different context. Leapseconds are never counted. -
MILLI_OF_SECOND
Element with the millisecond in the value range
0-999
. -
MICRO_OF_SECOND
Element with the microsecond in the value range
0-999999
. -
NANO_OF_SECOND
@FormattableElement(format="S") public static final ProportionalElement<Integer,PlainTime> NANO_OF_SECONDElement with the nanosecond in the value range
0-999999999
. -
MILLI_OF_DAY
@FormattableElement(format="A") public static final ProportionalElement<Integer,PlainTime> MILLI_OF_DAYElement with the day time in milliseconds in the value range
0-86400000
.Given a context of
PlainTime
with full milliseconds, the maximum is86400000
and stands for the time 24:00 (midnight at end of day), else the maximum is86399999
in every different context. Leapseconds are never counted. -
MICRO_OF_DAY
Element with the day time in microseconds in the value range
0-86400000000
.Given a context of
PlainTime
with full microseconds, the maximum is86400000000
and stands for the time 24:00 (midnight at end of day), else the maximum is86399999999
in every different context. Leapseconds are never counted. -
NANO_OF_DAY
Element with the day time in nanoseconds in the value range
0-86400000000000
.Given any context of
PlainTime
, the maximum is always86400000000000
and stands for the time 24:00 (midnight at end of day), else the maximum is86399999999999
in every different context. Leapseconds are never counted.Example:
import static net.time4j.ClockUnit.HOURS; import static net.time4j.PlainTime.NANO_OF_DAY; PlainTime time = PlainTime.midnightAtStartOfDay().plus(6, HOURS); // T06:00 System.out.println( time.get(NANO_OF_DAY.ratio()) .multiply(BigDecimal.ofHour(100)).stripTrailingZeros() + "% of day are over."); // Output: 25% of day are over.
-
DECIMAL_HOUR
Decimal hour in the value range
0.0
inclusive until24.0
exclusive (inclusive inPlainTime
).This element does not define any base unit.
-
DECIMAL_MINUTE
Decimal minute in the value range
0.0
inclusive until60.0
exclusive.This element does not define any base unit.
-
DECIMAL_SECOND
Decimal second in the value range
0.0
inclusive until60.0
exclusive.This element does not define any base unit.
-
PRECISION
Defines the precision as the smallest non-zero time element and truncates time parts of higher precision if necessary.
Setting higher precisions than available is without any effect. But setting lower precisions can truncate data however. Examples:
// reading of precision ------------------------------------- PlainTime time = PlainTime.of(12, 26, 52, 987654000); System.out.println(time.get(PRECISION)); // Output: MICROS // setting of precision ------------------------------------- PlainTime time = PlainTime.of(12, 26, 52, 987654000); System.out.println(time.with(PRECISION, ClockUnit.MILLIS)); // Output: T12:26:52,987
This element does not define any base unit.
-
-
Method Details
-
getHour
public int getHour()Description copied from interface:WallTime
Yields the hour of day.
-
getMinute
public int getMinute()Description copied from interface:WallTime
Yields the minute of hour.
-
getSecond
public int getSecond()Description copied from interface:WallTime
Yields the second of minute.
Given this context and the fact that this interface describes an analogue clock without UTC reference, the special leapsecond value
60
cannot be supported. -
getNanosecond
public int getNanosecond()Description copied from interface:WallTime
Yields the nanosecond.
Implementations which are not capable of nanosecond precision will just yield
0
or another suitable rounded value.- Specified by:
getNanosecond
in interfaceWallTime
- Returns:
- nanosecond in range
0 - 999,999,999
-
midnightAtStartOfDay
Yields midnight at the start of the day.
- Returns:
- midnight at the start of day T00:00
- See Also:
midnightAtEndOfDay()
-
midnightAtEndOfDay
Yields midnight at the end of the day, that is midnight at the start of the following day.
- Returns:
- midnight at the end of day T24:00
- See Also:
midnightAtStartOfDay()
-
of
Creates a wall time as full hour.
- Parameters:
hour
- iso-hour of day in the range0-24
- Returns:
- cached full hour
- Throws:
IllegalArgumentException
- if given hour is out of range
-
of
Creates a wall time with hour and minute.
- Parameters:
hour
- hour of day in the range0-23
or24
if the given minute equals to0
minute
- minute in the range0-59
- Returns:
- new or cached wall time
- Throws:
IllegalArgumentException
- if any argument is out of range
-
of
Creates a wall time with hour, minute and second.
- Parameters:
hour
- hour in the range0-23
or24
if the other arguments are equal to0
minute
- minute in the range0-59
second
- second in the range0-59
- Returns:
- new or cached wall time
- Throws:
IllegalArgumentException
- if any argument is out of range
-
of
Creates a wall time with hour, minute, second and nanosecond.
- Parameters:
hour
- hour in the range0-23
or24
if the other argumenta equal to0
minute
- minute in the range0-59
second
- second in the range0-59
nanosecond
- nanosecond in the range0-999,999,999
- Returns:
- new or cached wall time
- Throws:
IllegalArgumentException
- if any argument is out of range- See Also:
of(int)
,of(int, int)
,of(int, int, int)
,NANO_OF_SECOND
-
of
Creates a wall time by given decimal hour.
- Parameters:
decimal
- decimal hour of day in the range[0.0-24.0]
- Returns:
- new or cached wall time
- Throws:
IllegalArgumentException
- if the argument is out of range- See Also:
DECIMAL_HOUR
-
nowInSystemTime
Obtains the current clock time in system time.
Convenient short-cut for:
SystemClock.inLocalView().now().toTime()
.- Returns:
- current wall time (without zone) in system time zone using the system clock
- Since:
- 3.23/4.19
- See Also:
SystemClock.inLocalView()
,ZonalClock.now()
-
from
Common conversion method.
- Parameters:
time
- ISO-time- Returns:
- PlainTime
-
from
Short cut for
TemporalType.LOCAL_TIME.translate(time)
.- Parameters:
time
- Threeten-equivalent of this instance- Returns:
- PlainTime
- Since:
- 4.0
- See Also:
TemporalType.LOCAL_TIME
-
plus
Adds given amount in units to this clock time and yields the result of addition.
Covers the most important units and is overloaded for performance reasons.
- Parameters:
amount
- the amount of units to be added to this clock time (maybe negative)unit
- the unit to be used in addition- Returns:
- result of addition as changed copy while this instance remains unaffected
- Throws:
ArithmeticException
- in case of numerical overflow- Since:
- 4.19
- See Also:
plus(long, IsoTimeUnit)
-
minus
Subtracts given amount in units from this clock time and yields the result of subtraction.
Covers the most important units and is overloaded for performance reasons.
- Parameters:
amount
- the amount of units to be subtracted from this clock time (maybe negative)unit
- the unit to be used in subtraction- Returns:
- result of subtraction as changed copy while this instance remains unaffected
- Throws:
ArithmeticException
- in case of numerical overflow- Since:
- 4.19
- See Also:
minus(long, IsoTimeUnit)
-
roll
Rolls this time by the given duration (as amount and unit) and also counts possible day overflow.
- Parameters:
amount
- amount to be added (maybe negative)unit
- time unit- Returns:
- result of rolling including possible day overflow
- See Also:
plus(long, IsoTimeUnit)
-
print
Creates a formatted output of this instance.
- Parameters:
printer
- helps to format this instance- Returns:
- formatted string
- Since:
- 5.0
-
parse
Parses given text to an instance of this class.
- Parameters:
text
- text to be parsedparser
- helps to parse given text- Returns:
- parsed result
- Throws:
IndexOutOfBoundsException
- if the text is emptyChronoException
- if the text is not parseable- Since:
- 5.0
-
equals
Compares the full state, that is hour, minute, second and nanosecond of this instance and given argument.
- Specified by:
equals
in classTimePoint<IsoTimeUnit,PlainTime>
- See Also:
TimePoint.compareTo(TimePoint)
-
hashCode
public int hashCode()Description copied from class:TimePoint
Subclasses must redefine this method corresponding to the behaviour of
equals()
.- Specified by:
hashCode
in classTimePoint<IsoTimeUnit,PlainTime>
-
isBefore
Description copied from interface:Temporal
Queries if this object is before given object on a timeline.
-
isAfter
Description copied from interface:Temporal
Queries if this object is after given object on a timeline.
-
isSimultaneous
Description copied from interface:Temporal
Queries if this object and given object have the same position on the time axis.
Is equivalent to
!isAfter(temporal) && !isBefore(temporal)
. This method differs from theObject
-methodequals()
such that first the comparison type must be a temporal one and second that only temporal-only state will be considered.- Specified by:
isSimultaneous
in interfaceTemporal<PlainTime>
- Parameters:
time
- object this instance is compared to- Returns:
true
if this instance is temporally equal totemporal
elsefalse
-
isMidnight
public boolean isMidnight()Is this instance at midnight, either at start or at end of day?
- Returns:
- boolean
-
compareTo
Defines a natural order which is solely based on the timeline order.
The natural order is consistent with
equals()
.- Specified by:
compareTo
in interfaceComparable<PlainTime>
- Specified by:
compareTo
in classTimePoint<IsoTimeUnit,PlainTime>
- See Also:
isBefore(PlainTime)
,isAfter(PlainTime)
-
toString
Dependent on the precision of this instance, this method yields a canonical representation in one of following formats (CLDR-syntax):
- 'T'HH
- 'T'HH:mm
- 'T'HH:mm:ss
- 'T'HH:mm:ss,SSS
- 'T'HH:mm:ss,SSSSSS
- 'T'HH:mm:ss,SSSSSSSSS
The fraction part will be preceded by a comma as recommended by ISO unless the system property "net.time4j.format.iso.decimal.dot" was set to "true".
-
toTemporalAccessor
Description copied from interface:ThreetenAdapter
Converts this object to a
TemporalAccessor
.Any implementation is required to return a new object with a different concrete type, not this instance.
- Specified by:
toTemporalAccessor
in interfaceThreetenAdapter
- Returns:
- converted Threeten-object (always as new object)
-
getFormatPattern
Description copied from interface:LocalizedPatternSupport
Defines a CLDR-compatible localized format pattern suitable for printing.
The default implementation delegates to the underlying chronology.
- Specified by:
getFormatPattern
in interfaceLocalizedPatternSupport
- Parameters:
style
- format stylelocale
- language and country setting- Returns:
- localized format pattern
-
axis
Provides a static access to the associated time axis respective chronology which contains the chronological rules.
- Returns:
- chronological system as time axis (never
null
)
-
threeten
Obtains a bridge chronology for the type
java.time.LocalTime
.- Returns:
- rule engine adapted for the type
java.time.LocalTime
- Since:
- 5.0
- See Also:
axis()
-