3

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.

Paul Warnick
  • 903
  • 2
  • 13
  • 26
  • You're probably getting off track when calculating the extra day in February on a leap __year__ . Using option 2 therefore isn't the right choice. Adding 0.25 for each year isn't accurate either, as the quarter day isn't really added to the UTC only when it accumulates to a full day. – Mordechai Feb 03 '17 at 21:20
  • Couldn't you just do something like `((currentDate().getTime() - startOf2004.getTime()) / 1000) + 37`? `java.util.Date#getTime()` gives you the milliseconds since Epoch for that time instant. – Mick Mnemonic Feb 03 '17 at 21:20
  • 1
    Multiplying by either 365 or 365.25 is only approximate. There are 34 years from 1970 to 2004, 8 of which are leap years, which works out to 12,418 days. – Gerard Ashton Feb 04 '17 at 10:27

1 Answers1

0

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
Meno Hochschild
  • 42,708
  • 7
  • 104
  • 126