Easy way to get the International Atomic Time on linux?
772
My system uses UTC for the system clock, which I don't particularly feel like changing. Is there an easy way to get the current TAI time? (preferably a command line tool or flag)
The answer with the "right/" timezone is incorrect. It is meant to convert from a system clock kept in TAI - 10s to UTC. Thus, the following gives the correct time in UTC, GPS, LOREN and TAI [1]:
#!/bin/sh
echo -n "UTC: "; TZ='UTC' date
echo -n "GPS: "; TZ='UTC' date --date='TZ="../leaps/UTC" now -9 seconds'
echo -n "LORAN: "; TZ='UTC' date --date='TZ="../leaps/UTC" now'
echo -n "TAI: "; TZ='UTC' date --date='TZ="../leaps/UTC" now 10 seconds'
The right timezones might be at a different location, TZ="right/UTC", TZ="../zoneinfo-leaps/UTC". Replace "now" with the date/time you want to transform - the output is correct for every date after 1/1/1980.
Output:
UTC: Sun Oct 30 16:28:30 UTC 2016
GPS: Sun Oct 30 16:28:47 UTC 2016
LORAN: Sun Oct 30 16:28:56 UTC 2016
TAI: Sun Oct 30 16:29:06 UTC 2016
There is work in progress to give Linux native support for TAI. Until then, you can use scheme-clock to convert to TAI.
The answer with the "right/" timezone is incorrect. It is meant to convert from a system clock kept in TAI - 10s to UTC. Thus, the following gives the correct time in UTC, GPS, LOREN and TAI [1]:
The right timezones might be at a different location, TZ="right/UTC", TZ="../zoneinfo-leaps/UTC". Replace "now" with the date/time you want to transform - the output is correct for every date after 1/1/1980.
Output:
[1] http://www.leapsecond.com/java/gpsclock.htm
Answer is Deprecated: see https://serverfault.com/a/812163/67419
You could use the "right/" timezone to display an approximation (<1s) of the TAI.
But you need to make sure that your timezone package is up-to-date (e.g. tzdata on Ubuntu).
Code:
Example:
Reason for depreciation: between 2013 and today, the timezone "right/UTC" corresponds to TAI - 10 seconds and not TAI. Or there was a bug.
It's easy to do: just run
/usr/sbin/ntpdate pool.ntp.org;/sbin/hwclock --systohc
once or add it to cron. I have it set to daily.