Package com.teamdev.jxbrowser.time
Interface Timestamp
public interface Timestamp
A point in time independent of any time zone or calendar, represented as milliseconds in UTC Unix
Epoch time.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic TimestampfromInstant(Instant instant) Creates aTimestampfrom the givenInstant.static TimestampfromMicros(long microseconds) Creates aTimestampfrom the number of microseconds of UTC time since Unix epoch 1970-01-01T00:00:00Z.static TimestampfromMillis(long milliseconds) Creates aTimestampfrom the number of milliseconds of UTC time since Unix epoch 1970-01-01T00:00:00Z.static TimestampfromSeconds(long seconds) Creates aTimestampfrom the number of seconds of UTC time since Unix epoch 1970-01-01T00:00:00Z.default InstantConverts thisTimestampto anInstant.default longtoMicros()Returns the number of microseconds of UTC time since Unix epoch 1970-01-01T00:00:00Z.default longtoMillis()Returns the number of milliseconds of UTC time since Unix epoch 1970-01-01T00:00:00Z.default longReturns the number of seconds of UTC time since Unix epoch 1970-01-01T00:00:00Z.
-
Field Details
-
NONE
TheTimestampfrom the number of microseconds of UTC time since Unix epoch 1970-01-01T00:00:00Z set to none. -
MAX
The maximum allowedTimestampof UTC time since Unix epoch. An equivalent to 9999-12-31T23:59:59Z.
-
-
Method Details
-
fromSeconds
Creates aTimestampfrom the number of seconds of UTC time since Unix epoch 1970-01-01T00:00:00Z.- Parameters:
seconds- the number of seconds of UTC time since Unix epoch 1970-01-01T00:00:00Z- Returns:
- a
Timestampfrom the number of seconds of UTC time since Unix epoch - Throws:
IllegalArgumentException- when thesecondsargument is negative
-
fromMillis
Creates aTimestampfrom the number of milliseconds of UTC time since Unix epoch 1970-01-01T00:00:00Z.- Parameters:
milliseconds- the number of milliseconds of UTC time since Unix epoch 1970-01-01T00:00:00Z- Returns:
- a
Timestampfrom the number of milliseconds of UTC time since Unix epoch - Throws:
IllegalArgumentException- when themillisecondsargument is negative
-
fromMicros
Creates aTimestampfrom the number of microseconds of UTC time since Unix epoch 1970-01-01T00:00:00Z.- Parameters:
microseconds- the number of microseconds of UTC time since Unix epoch 1970-01-01T00:00:00Z- Returns:
- a
Timestampfrom the number of microseconds of UTC time since Unix epoch - Throws:
IllegalArgumentException- when themicrosecondsargument is negative
-
fromInstant
Creates aTimestampfrom the givenInstant.Instantis based on nanosecond precision, whileTimestampis based on microseconds. SinceTimestamphas less precision, any additional nanoseconds in theInstantwill be truncated. This does not result in a loss of precision relevant toTimestamp, as it cannot store nanoseconds.- Parameters:
instant- anInstantto create aTimestampfrom- Returns:
- a
Timestampthat represents the same point in time as the givenInstant, truncated to microsecond precision
-
toMicros
default long toMicros()Returns the number of microseconds of UTC time since Unix epoch 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z inclusive.- Returns:
- the number of microseconds of UTC time since Unix epoch
-
toMillis
default long toMillis()Returns the number of milliseconds of UTC time since Unix epoch 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z inclusive.- Returns:
- the number of milliseconds of UTC time since Unix epoch
-
toSeconds
default long toSeconds()Returns the number of seconds of UTC time since Unix epoch 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z inclusive.- Returns:
- the number of seconds of UTC time since Unix epoch
-
toInstant
Converts thisTimestampto anInstant.Timestampis based on microseconds, whileInstantoffers nanosecond precision. SinceTimestampis less precise, the conversion toInstantwill not result in any loss of precision. The additional nanoseconds are simply set to zero.- Returns:
- an instance of
Instantthat represents the same point in time as thisTimestamp
-