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:
COMPONENTAM_PM_OF_DAYCLOCK_HOUR_OF_AMPMCLOCK_HOUR_OF_DAYDIGITAL_HOUR_OF_AMPMDIGITAL_HOUR_OF_DAYHOUR_FROM_0_TO_24MINUTE_OF_HOURMINUTE_OF_DAYSECOND_OF_MINUTESECOND_OF_DAYMILLI_OF_SECONDMICRO_OF_SECONDNANO_OF_SECONDMILLI_OF_DAYMICRO_OF_DAYNANO_OF_DAYPRECISIONDECIMAL_HOURDECIMAL_MINUTEDECIMAL_SECOND
- Author:
- Meno Hochschild
- See Also:
- Serialized Form
-
Field Summary
FieldsModifier 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 WallTimeElementElement with the wall time in the value range[T00:00:00,000000000]until[T24:00:00,000000000](inclusive in the context ofPlainTimeelse exclusive).static ZonalElement<BigDecimal>Decimal hour in the value range0.0inclusive until24.0exclusive (inclusive inPlainTime).static ZonalElement<BigDecimal>Decimal minute in the value range0.0inclusive until60.0exclusive.static ZonalElement<BigDecimal>Decimal second in the value range0.0inclusive until60.0exclusive.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.intDefines a natural order which is solely based on the timeline order.booleanCompares the full state, that is hour, minute, second and nanosecond of this instance and given argument.static PlainTimeShort cut forTemporalType.LOCAL_TIME.translate(time).static PlainTimeCommon conversion method.getFormatPattern(FormatStyle style, Locale locale)Defines a CLDR-compatible localized format pattern suitable for printing.intgetHour()Yields the hour of day.intYields the minute of hour.intYields the nanosecond.intYields the second of minute.inthashCode()Subclasses must redefine this method corresponding to the behaviour ofequals().booleanQueries if this object is after given object on a timeline.booleanQueries if this object is before given object on a timeline.booleanIs this instance at midnight, either at start or at end of day?booleanisSimultaneous(PlainTime time)Queries if this object and given object have the same position on the time axis.static PlainTimeYields midnight at the end of the day, that is midnight at the start of the following day.static PlainTimeYields midnight at the start of the day.Subtracts given amount in units from this clock time and yields the result of subtraction.static PlainTimeObtains the current clock time in system time.static PlainTimeof(int hour)Creates a wall time as full hour.static PlainTimeof(int hour, int minute)Creates a wall time with hour and minute.static PlainTimeof(int hour, int minute, int second)Creates a wall time with hour, minute and second.static PlainTimeof(int hour, int minute, int second, int nanosecond)Creates a wall time with hour, minute, second and nanosecond.static PlainTimeof(BigDecimal decimal)Creates a wall time by given decimal hour.static PlainTimeparse(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, untilMethods inherited from class net.time4j.engine.ChronoEntity
contains, get, get, getInt, getMaximum, getMinimum, getRegisteredElements, getTimezone, hasTimezone, isValid, isValid, isValid, matches, with, with, with, withMethods inherited from interface net.time4j.format.LocalizedPatternSupport
getFormatPattern, useDynamicFormatPatternMethods inherited from interface net.time4j.engine.Temporal
isAfterAll, isAfterOrEqual, isBeforeAll, isBeforeOrEqualMethods 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 ofPlainTimeelse 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-20T00Note: 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
PlainTimewith full hours, the maximum is24and stands for the time 24:00 (midnight at end of day), else the maximum is23in 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
PlainTimewith full minutes, the maximum is1440and stands for the time 24:00 (midnight at end of day), else the maximum is1439in 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/60instead.- See Also:
getSecond()
-
SECOND_OF_DAY
Element with the second of day in the value range
0-86400.Given a context of
PlainTimewith full seconds, the maximum is86400and stands for the time 24:00 (midnight at end of day), else the maximum is86399in 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
PlainTimewith full milliseconds, the maximum is86400000and stands for the time 24:00 (midnight at end of day), else the maximum is86399999in 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
PlainTimewith full microseconds, the maximum is86400000000and stands for the time 24:00 (midnight at end of day), else the maximum is86399999999in 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 always86400000000000and stands for the time 24:00 (midnight at end of day), else the maximum is86399999999999in 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.0inclusive until24.0exclusive (inclusive inPlainTime).This element does not define any base unit.
-
DECIMAL_MINUTE
Decimal minute in the value range
0.0inclusive until60.0exclusive.This element does not define any base unit.
-
DECIMAL_SECOND
Decimal second in the value range
0.0inclusive until60.0exclusive.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:WallTimeYields the hour of day.
-
getMinute
public int getMinute()Description copied from interface:WallTimeYields the minute of hour.
-
getSecond
public int getSecond()Description copied from interface:WallTimeYields the second of minute.
Given this context and the fact that this interface describes an analogue clock without UTC reference, the special leapsecond value
60cannot be supported. -
getNanosecond
public int getNanosecond()Description copied from interface:WallTimeYields the nanosecond.
Implementations which are not capable of nanosecond precision will just yield
0or another suitable rounded value.- Specified by:
getNanosecondin 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-23or24if the given minute equals to0minute- 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-23or24if the other arguments are equal to0minute- minute in the range0-59second- 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-23or24if the other argumenta equal to0minute- minute in the range0-59second- second in the range0-59nanosecond- 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:
equalsin classTimePoint<IsoTimeUnit,PlainTime>- See Also:
TimePoint.compareTo(TimePoint)
-
hashCode
public int hashCode()Description copied from class:TimePointSubclasses must redefine this method corresponding to the behaviour of
equals().- Specified by:
hashCodein classTimePoint<IsoTimeUnit,PlainTime>
-
isBefore
Description copied from interface:TemporalQueries if this object is before given object on a timeline.
-
isAfter
Description copied from interface:TemporalQueries if this object is after given object on a timeline.
-
isSimultaneous
Description copied from interface:TemporalQueries 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:
isSimultaneousin interfaceTemporal<PlainTime>- Parameters:
time- object this instance is compared to- Returns:
trueif this instance is temporally equal totemporalelsefalse
-
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:
compareToin interfaceComparable<PlainTime>- Specified by:
compareToin 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:ThreetenAdapterConverts this object to a
TemporalAccessor.Any implementation is required to return a new object with a different concrete type, not this instance.
- Specified by:
toTemporalAccessorin interfaceThreetenAdapter- Returns:
- converted Threeten-object (always as new object)
-
getFormatPattern
Description copied from interface:LocalizedPatternSupportDefines a CLDR-compatible localized format pattern suitable for printing.
The default implementation delegates to the underlying chronology.
- Specified by:
getFormatPatternin 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()
-