Package org.scictrl.csshell
Class Timestamp
java.lang.Object
org.scictrl.csshell.Timestamp
- All Implemented Interfaces:
Comparable<Timestamp>
This is timestamp object with nanosecond resolution. It holds two long values. One is with millisoecnd
resolution and represents Java standart UTC format. Second long value is with nanosecond resolution
and its absolute value is lower than 1ms or 1000000ns.
- Author:
- igor@scictrl.com
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintcompareTo.booleanlongReturns time in milliseconds since epoch (standard Java UTC time, as returned by System.currentTimeMillis())longGetter for the fieldnanoseconds.longGet seconds since epoch, i.e.booleanisGreaterOrEqual(Timestamp other) isGreaterOrEqual.booleanisGreaterThan(Timestamp other) isGreaterThan.booleanisLessOrEqual(Timestamp other) isLessOrEqual.booleanisLessThan(Timestamp other) isLessThan.booleanisValid()isValid.doubletoDouble()Converts timestamp to double.longReturns time in nanoseconds since epoch.toString()toString(Timestamp.Format format) toString.
-
Constructor Details
-
Timestamp
public Timestamp()Default constructor, uses system time for initialization. -
Timestamp
public Timestamp(long milli, long nano) Creates timestamp representing provided values. If nanoseconds exceed 1000000 or -1000000 then they are truncated to nanoseconds within millisecond and millisecond is corrected.- Parameters:
milli- a longnano- a long
-
-
Method Details
-
getMilliseconds
public long getMilliseconds()Returns time in milliseconds since epoch (standard Java UTC time, as returned by System.currentTimeMillis())- Returns:
- Returns the milliseconds.
-
getNanoseconds
public long getNanoseconds()Getter for the field
nanoseconds.- Returns:
- Returns the nanoseconds within the millisecond.
-
compareTo
compareTo.
- Specified by:
compareToin interfaceComparable<Timestamp>- Parameters:
o- aTimestampobject- Returns:
- a int
-
toNanoTime
public long toNanoTime()Returns time in nanoseconds since epoch. Not that this in only usefull for calculating time difference for up to 292 years (263 nanoseconds) since this is maximum time possible in nanoseconds due to long value range overflow.- Returns:
- up to approx. 292 years big nano time
-
equals
-
toString
-
toString
toString.
- Parameters:
format- aTimestamp.Formatobject- Returns:
- Returns timestamp as string formated as specified.
-
getSeconds
public long getSeconds()Get seconds since epoch, i.e. 1 January 1970 0:00 UTC.- Returns:
- a long
-
toDouble
public double toDouble()Converts timestamp to double.- Returns:
- a double
-
isValid
public boolean isValid()isValid.
- Returns:
- Returns
trueif time fields > 0.
-
isGreaterThan
isGreaterThan.
- Parameters:
other- Other time stamp- Returns:
- Returns
trueif this time stamp is greater than theothertime stamp.
-
isGreaterOrEqual
isGreaterOrEqual.
- Parameters:
other- Other time stamp- Returns:
- Returns
trueif this time stamp is greater than or equal to theothertime stamp.
-
isLessThan
isLessThan.
- Parameters:
other- Other time stamp- Returns:
- Returns
trueif this time stamp is less than theothertime stamp.
-
isLessOrEqual
isLessOrEqual.
- Parameters:
other- Other time stamp- Returns:
- Returns
trueif this time stamp is less than or equal to theothertime stamp.
-