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.COMPONENT
PlainDate.YEAR
PlainDate.YEAR_OF_WEEKDATE
PlainDate.QUARTER_OF_YEAR
PlainDate.MONTH_OF_YEAR
PlainDate.MONTH_AS_NUMBER
PlainDate.DAY_OF_MONTH
PlainDate.DAY_OF_QUARTER
PlainDate.DAY_OF_WEEK
PlainDate.DAY_OF_YEAR
PlainDate.WEEKDAY_IN_MONTH
PlainTime.COMPONENT
PlainTime.AM_PM_OF_DAY
PlainTime.CLOCK_HOUR_OF_AMPM
PlainTime.CLOCK_HOUR_OF_DAY
PlainTime.DIGITAL_HOUR_OF_AMPM
PlainTime.DIGITAL_HOUR_OF_DAY
PlainTime.HOUR_FROM_0_TO_24
PlainTime.MINUTE_OF_HOUR
PlainTime.MINUTE_OF_DAY
PlainTime.SECOND_OF_MINUTE
PlainTime.SECOND_OF_DAY
PlainTime.MILLI_OF_SECOND
PlainTime.MICRO_OF_SECOND
PlainTime.NANO_OF_SECOND
PlainTime.MILLI_OF_DAY
PlainTime.MICRO_OF_DAY
PlainTime.NANO_OF_DAY
PlainTime.DECIMAL_HOUR
PlainTime.DECIMAL_MINUTE
PlainTime.DECIMAL_SECOND
PlainTime.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.int
compareTo(PlainTimestamp timestamp)
Defines the temporal order of date and time as natural order.boolean
Compares the whole state of this instance with given object.static PlainTimestamp
from(LocalDateTime ldt)
Short cut forTemporalType.LOCAL_DATE_TIME.translate(ldt)
.Provides the calendar date part.int
Yields the day of month.int
getHour()
Yields the hour of day.int
Yields the minute of hour.int
getMonth()
Yields the gregorian month as integer.int
Yields the nanosecond.int
Yields the second of minute.Provides the wall time part.int
getYear()
Yields the proleptic year according to ISO-8601.int
hashCode()
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.boolean
isAfter(PlainTimestamp timestamp)
Queries if this object is after given object on a timeline.boolean
isBefore(PlainTimestamp timestamp)
Queries if this object is before given object on a timeline.boolean
isSimultaneous(PlainTimestamp timestamp)
Queries if this object and given object have the same position on the time axis.boolean
Does 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 PlainTimestamp
Obtains the current timestamp in system time.static PlainTimestamp
of(int year, int month, int dayOfMonth, int hour, int minute)
Creates a new local timestamp in minute precision.static PlainTimestamp
of(int year, int month, int dayOfMonth, int hour, int minute, int second)
Creates a new local timestamp in second precision.static PlainTimestamp
Creates a new local timestamp with calendar date and wall time.static PlainTimestamp
parse(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, 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, 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
-
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-23
or24
if minute and second are equal to0
minute
- 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-23
or24
if minute and second are equal to0
minute
- minute in the range0-59
second
- 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:GregorianDate
Yields 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:
getYear
in interfaceGregorianDate
- Returns:
- proleptic iso year in range
GregorianMath.MIN_YEAR
-GregorianMath.MAX_YEAR
-
getMonth
public int getMonth()Description copied from interface:GregorianDate
Yields the gregorian month as integer.
- Specified by:
getMonth
in interfaceGregorianDate
- Returns:
- gregorian month in range (1 = January, ..., 12 = December)
-
getDayOfMonth
public int getDayOfMonth()Description copied from interface:GregorianDate
Yields the day of month.
- Specified by:
getDayOfMonth
in interfaceGregorianDate
- Returns:
- day of month in range
1 <= dayOfMonth <= 31
-
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
-
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:Temporal
Queries if this object is before given object on a timeline.
- Specified by:
isBefore
in interfaceTemporal<PlainTimestamp>
- Parameters:
timestamp
- object this instance is compared to- Returns:
true
if this instance is temporally beforetemporal
elsefalse
-
isAfter
Description copied from interface:Temporal
Queries if this object is after given object on a timeline.
- Specified by:
isAfter
in interfaceTemporal<PlainTimestamp>
- Parameters:
timestamp
- object this instance is compared to- Returns:
true
if this instance is temporally aftertemporal
elsefalse
-
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<PlainTimestamp>
- Parameters:
timestamp
- object this instance is compared to- Returns:
true
if this instance is temporally equal totemporal
elsefalse
-
compareTo
Defines the temporal order of date and time as natural order.
The comparison is consistent with
equals()
.- Specified by:
compareTo
in interfaceComparable<PlainTimestamp>
- Specified by:
compareTo
in classTimePoint<IsoUnit,PlainTimestamp>
- See Also:
isBefore(PlainTimestamp)
,isAfter(PlainTimestamp)
-
equals
Description copied from class:TimePoint
Compares 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:
equals
in classTimePoint<IsoUnit,PlainTimestamp>
- 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<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:
toString
in interfaceGregorianDate
- Specified by:
toString
in interfaceWallTime
- Specified by:
toString
in 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: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)
-
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:
true
if 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:
normalize
in 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)
-