I am working on a Java7 project, and we need a timestamp in International Atomic Time. I've found a few other questions relating to this that point to JSR-310 and ThreeTen Project (which is implementing JSR-310):
How to get GPS Time and TAI time in Java?
http://www.coderanch.com/t/549178/java/java/TAI-Atomic-Time-International
However, I'm struggling to work out exactly what to use for Java 7 and where to get it from. There seems to be old SourceForge & GitHub pages for ThreeTen, as well as an OpenJDK page.
I've found the Java 7 backport, but after downloading this from Maven it doesn't include the TAIInstant class, which is what I actually need (the TIAInstant class is listed on the ThreeTen SourceForge JavaDoc, under javax.time.TAIInstant).
For completeness, this is the excerpt from my pom.xml:
<dependency>
<groupId>org.threeten</groupId>
<artifactId>threetenbp</artifactId>
<version>0.8.1</version>
</dependency>
Should I be using something else, and where should I be getting it from?
Note: Sorry I'm not able to provide links to all the pages I'm referring to, StackOverflow won't let me have > 2 links per post without higher rep.
[EDIT]
The reason for wanting TAI is that I need a timestamp which is monotonically increasing, which I believe TAI fulfils (even during both positive & negative leap seconds, since it doesn't care about leap seconds counts all seconds equally, including leap seconds).
Having read about POSIX / Unix time from various sources it's still not clear to me exactly what happens in Unix Time over a leap second. I know the Unix Time is ambiguous in terms of referring to a UTC Time, but I'm not clear on what happens in Unix Time in the instant a leap second occurs? Does Unix Time 'pause' or go backwards for example? And perhaps more importantly, even if it shouldn't according to the Unix Time spec, do Unix implementations actually obey the spec regarding leap seconds...?
Finally, Am I correct in saying that System.currentTimeMillis() will get the equivalent of POSIX Time (albeit in milliseconds rather than seconds)?
Note, I need an object which is portable across JVMs and machines (ruling out System.nanoTime() or similar).
[CONCLUSION]
TAI
TAI is a system of measuring time where every second is counted and 'all seconds are equal' - ie. every second consists of the same period of time, and all seconds (including leap seconds) are counted in the total. This means the number of seconds in TAI (counted from some arbitrary start point, the Unix Epoch for example) is a monotonically increasing integer.
POSIX Time
POSIX Time is a standard (NOT an implementation) for measuring time. It defines every day as having exactly 86400 seconds. Therefore, POSIX time does not count leap seconds (since occasionally a minute may have 61 seconds, leading to days with >86400 seconds, and theoretically a minute could have 59 seconds, leading to days with <86400 seconds). This means that 'seconds' in POSIX have variable length, and shortly before / during / after leap seconds, a POSIX clock may skip seconds or repeat them. Specifically, the POSIX spec as referenced by Meno Hochschild in his answer states, "The relationship between the actual time of day and the current value for seconds since the Epoch is unspecified."
UTC
UTC is a time standard which is related to the way the Earth moves around the Sun, aiming to maintain the relationship between the position of the Sun and the time of day (within a threshold). Ie in a UTC+0 region of the Earth, the Sun is always at its highest at midday UTC time. Leap Seconds (positive or negative) are necessary because the speed of the Earth's rotation is not fixed, and it does not vary in a predictable way (meaning we cannot predict when leap seconds will be necessary - or whether they will be positive leap seconds or negative leap seconds)
Representing Times
It seems to me that both TAI and POSIX are representations of 'counts of seconds' (ie. something easy for a computer to actually store), whereas UTC is a 'human interpretation' of time (ie. Year/Month/Day Hour:Minute:Second.millisecond) that is not usually stored internally by a computer.
Translating Times
Given the above, there are a number of issues translating from POSIX (without any leap seconds counted) to TAI (with leap seconds counted):
- It requires maintaining a table / count of leap seconds to translate any POSIX Time to a TAI Time
- Even if point 1 is addressed, the POSIX Spec as above makes no guarantee about what will happen during a leap second, so at such times we have no way of accurately representing an unambiguous time
- If a number of systems must communicate, passing timestamps between them, we must guarantee that the table / count of leap seconds is kept consistent
On the other hand, it is easy to convert from POSIX to the UTC 'human interpretation'. It doesn't require knowledge of leap seconds, since it just assumes every day has the same number of seconds (albeit some of these 'seconds' have different lengths of time in reality). In practice, you would just use the inverse of the formula in the POSIX Spec to obtain various the UTC components of time (again, see the POSIX spec referenced by Meno Hochschild).