Class PlainTimestamp
- All Implemented Interfaces:
Serializable,Comparable<PlainTimestamp>,TemporalAccessor,GregorianDate,WallTime,ChronoDisplay,Normalizer<IsoUnit>,Temporal<PlainTimestamp>,ThreetenAdapter,LocalizedPatternSupport
Represents a plain composition of calendar date and wall time as defined in ISO-8601, but without any timezone.
Following elements which are declared as constants are registered by this class:
PlainDate.COMPONENTPlainDate.YEARPlainDate.YEAR_OF_WEEKDATEPlainDate.QUARTER_OF_YEARPlainDate.MONTH_OF_YEARPlainDate.MONTH_AS_NUMBERPlainDate.DAY_OF_MONTHPlainDate.DAY_OF_QUARTERPlainDate.DAY_OF_WEEKPlainDate.DAY_OF_YEARPlainDate.WEEKDAY_IN_MONTHPlainTime.COMPONENTPlainTime.AM_PM_OF_DAYPlainTime.CLOCK_HOUR_OF_AMPMPlainTime.CLOCK_HOUR_OF_DAYPlainTime.DIGITAL_HOUR_OF_AMPMPlainTime.DIGITAL_HOUR_OF_DAYPlainTime.HOUR_FROM_0_TO_24PlainTime.MINUTE_OF_HOURPlainTime.MINUTE_OF_DAYPlainTime.SECOND_OF_MINUTEPlainTime.SECOND_OF_DAYPlainTime.MILLI_OF_SECONDPlainTime.MICRO_OF_SECONDPlainTime.NANO_OF_SECONDPlainTime.MILLI_OF_DAYPlainTime.MICRO_OF_DAYPlainTime.NANO_OF_DAYPlainTime.DECIMAL_HOURPlainTime.DECIMAL_MINUTEPlainTime.DECIMAL_SECONDPlainTime.PRECISION
Furthermore, all elements of class Weekmodel are supported. As
timestamp units can be used: CalendarUnit and ClockUnit.
Note: The special time value 24:00 is only supported in the factory methods which normalize the resulting timestamp to midnight of the following day. In element access and manipulations this value is not supported.
- Author:
- Meno Hochschild
- See Also:
- Serialized Form
-
Method Summary
Modifier and TypeMethodDescriptionat(ZonalOffset offset)Combines this local timestamp with the given timezone offset to a global UTC-moment.atUTC()Combines this local timestamp with the timezone offset UTC+00:00 to a global UTC-moment.static TimeAxis<IsoUnit,PlainTimestamp>axis()Provides a static access to the associated time axis respective chronology which contains the chronological rules.intcompareTo(PlainTimestamp timestamp)Defines the temporal order of date and time as natural order.booleanCompares the whole state of this instance with given object.static PlainTimestampfrom(LocalDateTime ldt)Short cut forTemporalType.LOCAL_DATE_TIME.translate(ldt).Provides the calendar date part.intYields the day of month.intgetHour()Yields the hour of day.intYields the minute of hour.intgetMonth()Yields the gregorian month as integer.intYields the nanosecond.intYields the second of minute.Provides the wall time part.intgetYear()Yields the proleptic year according to ISO-8601.inthashCode()Subclasses must redefine this method corresponding to the behaviour ofequals().Combines this local timestamp with given timezone to a global UTC-moment.Equivalent toinZonalView(Timezone.ofSystem().Combines this local timestamp with the system timezone to a global UTC-moment.inTimezone(TZID tzid)Combines this local timestamp with given timezone to a global UTC-moment.inZonalView(Timezone tz)Converts this instance to a combination of UTC-moment, given timezone and its zonal timestamp.booleanisAfter(PlainTimestamp timestamp)Queries if this object is after given object on a timeline.booleanisBefore(PlainTimestamp timestamp)Queries if this object is before given object on a timeline.booleanisSimultaneous(PlainTimestamp timestamp)Queries if this object and given object have the same position on the time axis.booleanDoes this local timestamp exist in given timezone?minus(long amount, CalendarUnit unit)Subtracts given amount in units from this timestamp and yields the result of subtraction.Subtracts given amount in units from this timestamp and yields the result of subtraction.Normalizes given timespan using years, months, days and all clock units.static PlainTimestampObtains the current timestamp in system time.static PlainTimestampof(int year, int month, int dayOfMonth, int hour, int minute)Creates a new local timestamp in minute precision.static PlainTimestampof(int year, int month, int dayOfMonth, int hour, int minute, int second)Creates a new local timestamp in second precision.static PlainTimestampCreates a new local timestamp with calendar date and wall time.static PlainTimestampparse(String text, TemporalFormatter<PlainTimestamp> parser)Parses given text to an instance of this class.plus(long amount, CalendarUnit unit)Adds given amount in units to this timestamp and yields the result of addition.Adds given amount in units to this timestamp and yields the result of addition.print(TemporalFormatter<PlainTimestamp> printer)Creates a formatted output of this instance.static Chronology<LocalDateTime>threeten()Obtains a bridge chronology for the typejava.time.LocalDateTime.toDate()Synonym forgetCalendarDate().toString()Creates a canonical representation of the form "yyyy-MM-dd'T'HH:mm:ss,fffffffff".Converts this object to aTemporalAccessor.toTime()Synonym forgetWallTime().with(ElementOperator<?> operator)Adjusts this timestamp by given operator.Adjusts the calendar part of this timestamp.Adjusts the wall time part of this timestamp.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, 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
-
Method Details
-
of
Creates a new local timestamp with calendar date and wall time.
The special time value 24:00 will automatically normalized such that the resulting timestamp is on starting midnight of following day.
- Parameters:
date- calendar date componenttime- wall time component (24:00 will always be normalized)- Returns:
- timestamp as composition of date and time
- See Also:
of(int, int, int, int, int),of(int, int, int, int, int, int)
-
of
Creates a new local timestamp in minute precision.
The special time value 24:00 will automatically normalized such that the resulting timestamp is on starting midnight of following day.
- Parameters:
year- proleptic iso year [(-999,999,999)-999,999,999]month- gregorian month in range (1-12)dayOfMonth- day of month in range (1-31)hour- hour in the range0-23or24if minute and second are equal to0minute- minute in the range0-59- Returns:
- timestamp as composition of date and time
-
of
public static PlainTimestamp of(int year, int month, int dayOfMonth, int hour, int minute, int second)Creates a new local timestamp in second precision.
The special time value 24:00 will automatically normalized such that the resulting timestamp is on starting midnight of following day.
- Parameters:
year- proleptic iso year [(-999,999,999)-999,999,999]month- gregorian month in range (1-12)dayOfMonth- day of month in range (1-31)hour- hour in the range0-23or24if minute and second are equal to0minute- minute in the range0-59second- second in the range0-59- Returns:
- timestamp as composition of date and time
-
nowInSystemTime
Obtains the current timestamp in system time.
Convenient short-cut for:
SystemClock.inLocalView().now().- Returns:
- current timestamp (without zone) in system time zone using the system clock
- Since:
- 3.23/4.19
- See Also:
SystemClock.inLocalView(),ZonalClock.now()
-
from
Short cut for
TemporalType.LOCAL_DATE_TIME.translate(ldt).- Parameters:
ldt- Threeten-equivalent of this instance- Returns:
- PlainTimestamp
- Since:
- 4.0
- See Also:
TemporalType.LOCAL_DATE_TIME
-
getCalendarDate
Provides the calendar date part.
- Returns:
- calendar date component
-
getWallTime
Provides the wall time part.
- Returns:
- wall time component
-
getYear
public int getYear()Description copied from interface:GregorianDateYields the proleptic year according to ISO-8601.
The term proleptic means that the gregorian calendar rules are applied backwards even before the introduction of this calendar. Second: The year numbering is just the mathematical one as defined in ISO-8601 such that there is a year zero and even negative years: -2 = BC 3, -1 = BC 2, 0 = BC 1, 1 = AD 1, 2 = AD 2, ...
- Specified by:
getYearin interfaceGregorianDate- Returns:
- proleptic iso year in range
GregorianMath.MIN_YEAR-GregorianMath.MAX_YEAR
-
getMonth
public int getMonth()Description copied from interface:GregorianDateYields the gregorian month as integer.
- Specified by:
getMonthin interfaceGregorianDate- Returns:
- gregorian month in range (1 = January, ..., 12 = December)
-
getDayOfMonth
public int getDayOfMonth()Description copied from interface:GregorianDateYields the day of month.
- Specified by:
getDayOfMonthin interfaceGregorianDate- Returns:
- day of month in range
1 <= dayOfMonth <= 31
-
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
-
with
Adjusts this timestamp by given operator.
- Parameters:
operator- element-related operator- Returns:
- changed copy of this timestamp
- See Also:
ChronoEntity.with(net.time4j.engine.ChronoOperator)
-
with
Adjusts the calendar part of this timestamp.
- Parameters:
date- new calendar date component- Returns:
- changed copy of this timestamp
- See Also:
PlainDate.COMPONENT
-
with
Adjusts the wall time part of this timestamp.
- Parameters:
time- new wall time component- Returns:
- changed copy of this timestamp
- See Also:
PlainTime.COMPONENT
-
isBefore
Description copied from interface:TemporalQueries if this object is before given object on a timeline.
- Specified by:
isBeforein interfaceTemporal<PlainTimestamp>- Parameters:
timestamp- object this instance is compared to- Returns:
trueif this instance is temporally beforetemporalelsefalse
-
isAfter
Description copied from interface:TemporalQueries if this object is after given object on a timeline.
- Specified by:
isAfterin interfaceTemporal<PlainTimestamp>- Parameters:
timestamp- object this instance is compared to- Returns:
trueif this instance is temporally aftertemporalelsefalse
-
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<PlainTimestamp>- Parameters:
timestamp- object this instance is compared to- Returns:
trueif this instance is temporally equal totemporalelsefalse
-
compareTo
Defines the temporal order of date and time as natural order.
The comparison is consistent with
equals().- Specified by:
compareToin interfaceComparable<PlainTimestamp>- Specified by:
compareToin classTimePoint<IsoUnit,PlainTimestamp>- See Also:
isBefore(PlainTimestamp),isAfter(PlainTimestamp)
-
equals
Description copied from class:TimePointCompares the whole state of this instance with given object.
Implementations will usually define their state only based on the temporal position on the time axis because this is the most intuitive approach. Exceptions from this rule should be explicitly documented and reasoned.
- Specified by:
equalsin classTimePoint<IsoUnit,PlainTimestamp>- 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<IsoUnit,PlainTimestamp>
-
toString
Creates a canonical representation of the form "yyyy-MM-dd'T'HH:mm:ss,fffffffff".
Dependent on the precision (that is last non-zero part of time) the time representation might be shorter.
- Specified by:
toStringin interfaceGregorianDate- Specified by:
toStringin interfaceWallTime- Specified by:
toStringin classTimePoint<IsoUnit,PlainTimestamp>- Returns:
- canonical ISO-8601-formatted string
- See Also:
PlainTime.toString()
-
toDate
Synonym for
getCalendarDate().- Returns:
- calendar date component
- Since:
- 3.6/4.4
- See Also:
getCalendarDate()
-
toTime
Synonym for
getWallTime().- Returns:
- wall time component
- Since:
- 3.6/4.4
- See Also:
getWallTime()
-
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
-
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)
-
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.LocalDateTime.- Returns:
- rule engine adapted for the type
java.time.LocalDateTime - Since:
- 5.0
- See Also:
axis()
-
atUTC
Combines this local timestamp with the timezone offset UTC+00:00 to a global UTC-moment.
- Returns:
- global UTC-moment based on this local timestamp interpreted at offset UTC+00:00
- See Also:
at(ZonalOffset)
-
at
Combines this local timestamp with the given timezone offset to a global UTC-moment.
- Parameters:
offset- timezone offset- Returns:
- global UTC-moment based on this local timestamp interpreted at given offset
- Since:
- 1.2
- See Also:
atUTC(),in(Timezone)
-
inStdTimezone
Combines this local timestamp with the system timezone to a global UTC-moment.
- Returns:
- global UTC-moment based on this local timestamp interpreted in system timezone
- Since:
- 1.2
- See Also:
Timezone.ofSystem(),inTimezone(TZID)
-
inTimezone
Combines this local timestamp with given timezone to a global UTC-moment.
- Parameters:
tzid- timezone id- Returns:
- global UTC-moment based on this local timestamp interpreted in given timezone
- Throws:
IllegalArgumentException- if given timezone cannot be loaded- Since:
- 1.2
- See Also:
Timezone.of(TZID),inStdTimezone()
-
in
Combines this local timestamp with given timezone to a global UTC-moment.
- Parameters:
tz- timezone- Returns:
- global UTC-moment based on this local timestamp interpreted in given timezone
- Since:
- 1.2
- See Also:
Timezone.of(String)
-
inLocalView
Equivalent to
inZonalView(Timezone.ofSystem().- Returns:
- ZonalDateTime
- Since:
- 3.16/4.13
-
inZonalView
Converts this instance to a combination of UTC-moment, given timezone and its zonal timestamp.
Attention: Due to winter/summer-time-changes the resulting zonal timestamp (
ZonalDateTime.toTimestamp()) can deviate from this plain timestamp.- Parameters:
tz- timezone- Returns:
- ZonalDateTime
- Since:
- 3.16/4.13
-
isValid
Does this local timestamp exist in given timezone?
- Parameters:
tzid- timezone id (optional)- Returns:
trueif this timestamp is valid in given timezone- Throws:
IllegalArgumentException- if given timezone cannot be loaded
-
normalize
Normalizes given timespan using years, months, days and all clock units.
This normalizer can also convert from days to months. Example:
Duration<CalendarUnit> dur = Duration.of(30, CalendarUnit.DAYS); Duration<IsoUnit> result = PlainTimestamp.of(2012, 2, 28, 0, 0).normalize(dur); System.out.println(result); // output: P1M1D (leap year!)- Specified by:
normalizein interfaceNormalizer<IsoUnit>- Parameters:
timespan- to be normalized- Returns:
- normalized duration
- Since:
- 2.0
- See Also:
Duration.with(Normalizer)
-
plus
Adds given amount in units to this timestamp and yields the result of addition.
Covers the most important calendar units and is overloaded for performance reasons.
- Parameters:
amount- the amount of units to be added to this timestamp (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, IsoUnit)
-
plus
Adds given amount in units to this timestamp and yields the result of addition.
Covers the most important clock units and is overloaded for performance reasons.
- Parameters:
amount- the amount of units to be added to this timestamp (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, IsoUnit)
-
minus
Subtracts given amount in units from this timestamp and yields the result of subtraction.
Covers the most important calendar units and is overloaded for performance reasons.
- Parameters:
amount- the amount of units to be subtracted from this timestamp (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, IsoUnit)
-
minus
Subtracts given amount in units from this timestamp and yields the result of subtraction.
Covers the most important clock units and is overloaded for performance reasons.
- Parameters:
amount- the amount of units to be subtracted from this timestamp (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, IsoUnit)
-