Converting TAI time to a Java Instant

537 Views Asked by At

I have access to TAI time with seconds and nano seconds - let me just called this T.

I want to now create a java Instant class corresponding to this value T.

I've looked for the appropriate constructors to do this but no luck.

2

There are 2 best solutions below

8
On

If you have access to the time elements separately you could do something like this:

long millisecondsTime = 1262347200000l;
long nanoseconds = 10202;
Instant taiInstance = Instant.ofEpochMilli(millisecondsTime);
taiInstance = taiInstance.plus(Duration.ofNanos(nanoseconds));
1
On

I'd recommend looking at, or using, the code in the ThreeTen-Extra library that explicity handles TAI and UTC. Here is the Javadoc.

TaiInstant tai = TaiInstant.ofTaiSeconds(taiSecs, taiNanos);
Instant instant = tai.toInstant();

The second method applies UTC-SLS conversion.