Finding the number of TAI seconds since 00:00:00 UTC, 1 January, 2004 in Java

1k Views Asked by At

As the title states, I'm required to find the number of TAI seconds since 00:00:00 UTC, January 1st, 2004 (in Java). I've just recently learned what TAI is and my attempts at working out the above have left me a bit confused.

What I've tried:

I know in Java you can use System.currentTimeMillis() to get the number of milliseconds since January 1st, 1970 UTC (Javadocs).

Additionally, from my brief research of atomic time I understand that currently TAI is exactly 37 (leap) seconds ahead of UTC.

Therefore, my thought process was to:

  1. Find the number of seconds between 1970 and 2004 (34 years)
  2. Subtract that from the current UTC time to get the number of since 2004
  3. Add 37 to get the actual number of seconds in TAI

I wasn't certain of the math here (1 day = 86400 seconds):

  • Option 1: 86400 (seconds) x 365.25 (days (1 Julian Year)) x 34 (years) = 1,072,958,400
  • Option 2: 86400 (seconds) x 365 (days (1 Common Year)) x 34 (years) = 1,072,224,000

At this point I started questioning whether the 37 leap seconds added to TAI were to account for leap years when comparing to UTC and thus I should use Option 2. Unfortunately, I'm not certain whether my thought process is correct and I figured it'd be better to ask here to make certain.

Also, I found this cite claiming that 1,072,915,200 (seconds) is equivalent to 01/01/2004 @ 12:00am (UTC). Which kind of threw me off because it's not equal to either of my calculations.

1

There are 1 best solutions below

0
On

Tai-seconds are essentially atomic SI-seconds including leap seconds. My library Time4J supports this feature out of the box. For more details about TAI-support see also the javadoc of class Moment:

Moment m2004 = PlainTimestamp.of(2004, 1, 1, 0, 0).atUTC();
Moment now = SystemClock.currentMoment(); // other clocks based on NTP are possible
long seconds = SI.SECONDS.between(m2004, now);

System.out.println(seconds); // 425222084L
System.out.println(now); // 2017-06-22T13:15:24,570000000Z