com.rcll.refbox.NanoSecondsTimestampProvider Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-sdk Show documentation
Show all versions of java-sdk Show documentation
Java SDK for the RoboCup Logistics League
package com.rcll.refbox;
/**
* The Class NanoSecondsTimestampProvider provides a timestamp in nanoseconds.
*/
class NanoSecondsTimestampProvider {
private long nanoSecondsOffset;
/**
* Instantiates a new NanoSecondsTimestampProvider.
*/
public NanoSecondsTimestampProvider() {
long curMilliSecs0, curMilliSecs1, curNanoSecs;
do {
curMilliSecs0 = System.currentTimeMillis();
curNanoSecs = System.nanoTime();
curMilliSecs1 = System.currentTimeMillis();
} while (curMilliSecs0 == curMilliSecs1);
nanoSecondsOffset = 1000000L * curMilliSecs1 - curNanoSecs;
}
/**
* Get the current time (UTC) in nanoseconds.
*
* @return the time in nanoseconds since midnight, January 1, 1970 UTC
*/
public long currentNanoSecondsTimestamp() {
return System.nanoTime() + nanoSecondsOffset;
}
}