Time
Timeanddate.com
Timezone date
TZ=Europe/Helsinki UTC+3h is UTC+2h + summer time EET+daylight saving time = EEST
The beginning of time
1847: GMT Time zone were introduced when rail travel spanned multiple timezones. GMT => TAI => UTC
1952:
1958: TAI = UT2
1967: Cs-133 A second was defined by the 13th General Conference on Weights and Measures: the duration of 9 192 631 770 cycles of microwave light absorbed or emitted by the hyperfine transition of cesium-133 atoms in their ground state undisturbed by external fields.
ET Ephemeris Time 1977: 1.0003725 TT = 1977 January 1.0000000 TAI
Time Formats
GMT is Greenwich Mean Time Z is Zulutime UT1 observed solar time TAI is international atomic time. UT + leapseconds UTC is Universal Coordinated Time
SI seconds (by BIPM) UTC (by ITU-R) BIH/IERS is responsible for leap seconds
ET - TAI = 32.184 seconds
ET - UT = ΔT
TT Terrestrial Time (new ET) a coordinate time scale at Earth's surface UT Universal Time UT is based on sidereal time, but with a scaling factor and other adjustments to make them closer to solar time. UT = UTC / UT1
UT0 is the rotational time observed as the diurnal motion of stars or extraterrestrial radio sources. UT1 is computed by correcting UT0 for the effect of polar motion UT2 is a smoothed version of UT1, filtering out periodic seasonal variations, hardly in use UT2R is a smoothed version of UT1, incorporating both the seasonal corrections of UT2 and the tidal corrections of UT1R
UNIX TIME seconds since 0:00 1 jan 1970
Standard time, observed v.s. coordinated. UTC Coordinated Universal Time is an atomic time scale designed to approximate Universal Time. UTC differs from TAI by an integral number of seconds
TAI International Atomic Time (primary realisation of Terrestrial Time)
- The "posix" version is based on the Coordinated Universal Time (UTC). - The "right" version is based on the International Atomic Time (TAI), and it includes the leap seconds.
Bulletin on the corrections between UTC and TAI http://hpiers.obspm.fr/iers/bul/bulc/bulletinc.dat from 2017 January 1, 0h UTC, until further notice : UTC-TAI = -37 s
Bulletin T on difference between UTC and UTC/NIST (synchronization delay/deviation) https://www.bipm.org/en/time-ftp/other-products
NIST runs NTP servers, most are UTC +/- a deviation in nanoseconds. 2 NTP servers report UT1.
The NIST servers will compute UT1 time by adding the DUT1 value for any MJD to UTC(NIST). The value used for DUT1 will be the value determined by http://www.iers.org
Programming Language
ISO Date Format
TimeDate formats
date %y%m%c
C
Java
https://www.joda.org/joda-time/apidocs/org/joda/time/format/DateTimeFormat.html
MYSQL / MARIADB
Oracle
Why circle 360, 24 timezones
The world turns around it's axis 365 times before it makes a circle around the sun.1 degree per day. Babylonians used base 60 and 6x 60 = 360 so it's neatly divisable.
24-hour per day ancient Egyptians who divided day-time into 10 hours they measured with devices such as shadow clocks, and added a twilight hour at the beginning and another one at the end of the day-time.
https://www.abc.net.au/science/articles/2011/11/15/3364432.htm
MST mean solar time
The length of the mean solar day is increasing due to the tidal acceleration of the Moon by Earth, and the corresponding deceleration of the Earth by the Moon.
1820 86400 Seconds +1.4 msec / 100 years +1.7 msec / 100 years
Mean Sidereal measured against a far away star. Time mean sidereal day is about 23 h 56 m 4.1 s in length
Computer Clock
Computers have a hardware clock for longtime clock keeping and the CPU keeps track of the software clock which is used in application to tell time. The software clock and hardware clock need to be calibrated, so it needs an external clock source.
My clock was running horribly wrong on my brand new computer. It's not a weak BIOS battery and it's not because it's a brand new AMD64. Heat will make clocks 'wobble' a bit, but the real reason was that I should have calibrated the clock. NTP will not correct clocks that are off by more than 500ms / minute. (or was it 500ms)
/etc/init.d/ntp stop ntpdate stampertje.islief.com hwclock --systohc adjtimex -a /etc/init.d/ntp start
Which clock?
An RTC / realtime hardware clock runs even when the computer is switched off. In the CPU a system clock loads the time from the hardware clock on startup, and updates the hardware clock on shutdown. NTP clocks on the internet provide a reliable time reference, some are directly linked to an atom clock. GPS satellites send precise time information and they have onboard atom clocks.
Hardware clock
http://support.ntp.org/bin/view/Support/KnownOsIssues
There are a few different available hardware clocks in modern PC's. The linux kernel will use one as the clocksource for interupts and also will use one system clock as the source.
cat /sys/devices/system/clocksource/clocksource0/current_clocksource acpi_pm
cat /sys/devices/system/clocksource/clocksource0/available_clocksource tsc hpet acpi_pm jiffies
The clocksource can be selected in the kernel options at bootup, so you can add clocksource to the kernel options.
vi /boot/grub/menu.lst kernel ... clocksource=hpet
The hardwareclock can be read or written from/to the systemclock using
hwclock --systohc hwclock --hctosys
The systemclock is updated every tick. A kernel generates by default roughly 100 ticks/second. To enhance the precision, the clock can be synchronized to the correct number of ticks and in my case the clock is always too slow, so I set the tick to 10003 which means that my system clock is not drifting as much as before. I previously incorrectly set the tick to 9700 causing a huge drift. adjtimex can calculate the difference between the systemclock and the hardware clock and will estimate what the tick should be. This is a very coarse setting, which can be fine tuned using NTP.
To print the current tick and freq
adjtimex -p
To adjust the tick / freq
adjtimex -a
/etc/init.d/adjtimex restart /etc/default/adjtimex TICK=100003 FREQ=4007068
Once the tick has been adjusted, and NTP is working the systemclock will be more accurate than the hardware clock. So the drift rate of the hardware clock will be calculated and stored. At startup it is calculated how much time the hardware clock has run undisciplined and the clocks will be corrected by the drift rate calculation.
cat /etc/adjtime
Ethernet TSN
https://en.wikipedia.org/wiki/Time-Sensitive_Networking
NTP
the NTP daemon will use clocksources from the internet to dicipline the system clock. it will first poll the time servers every 64 seconds until it has enough data to check less frequently (every 11 minutes). After a few polls NTP decides which clocksources are reliable (+) and which one it selects as the best (*) it will use. NTP will then slew the clock into the correct time, so a clock which is running 500ms fast will be slowly brought back to the correct time. The longer a clock is diciplined by NTP the more accurate it will be. network traffic will cause a delay between the client and the server, because the network latency increases, which will decrease accuracy. The ntp drift is stored in the driftfile so that the drift can be monitored.
A pool is a list of servers listed by DNS. In the DNS configuration.
https://www.vttresearch.com/fi/palvelut/suomen-aika-ntp-palvelu
server time.mikes.fi
sidn time.nl
pool ntp.time.nl
https://lg.telia.net/?type=bgp&router=fi-hkitm-asbr1.fi&address=194.100.49.139
https://developers.google.com/time/smear
time.google.com
https://aws.amazon.com/blogs/aws/look-before-you-leap-the-coming-leap-second-and-aws/
time.aws.com
https://tf.nist.gov/tf-cgi/servers.cgi
IPv6 https://www.iana.org/assignments/ipv6-multicast-addresses/ipv6-multicast-addresses.xhtml
FF0X::101 Network Time Protocol (NTP)
0 Reserved 1 Interface-Local scope 2 Link-Local scope 3 Realm-Local scope 4 Admin-Local scope 5 Site-Local scope 6-7 Unassigned 8 Organization-Local scope 9-D Unassigned E Global scope F Reserved
Chrony
https://ubuntu.com/server/docs/how-to-serve-the-network-time-protocol-with-chrony
chronyc makestep
chronyc sources chronyc sourcestats chronyc serverstats chronyc tracking
chronyc clients chronyc add server ntp.dnafinland.fi chronyc ntpdata
http://satsignal.eu/ntp/NTPandMRTG.html
https://store.uputronics.com/index.php?route=product/product&product_id=92
chrony can step the clock on the first 3 updates if the clock is off by more than one second. When the system doesn't have an RTC clock, this can be useful
makestep 1.0 3
When the system does have an RTC clock, chrony can sync the time
rtcsync
AWS and Google clock slewing
for the TAI correction, the AWS and Google NTP services slew the clock so the change is smeared out over a day, otherwise the clock could reach 23:59:60, which some applications (databases mainly) may not be able to cope.
OpenNTP
ntpq -np cat /var/lib/ntp/ntp.drift ntpdc -c kerninfo
NTP starting up (state 4) and not diciplining the clock yet (unsync)
pll offset: -0.063174 s pll frequency: -2.889 ppm maximum error: 0.076516 s estimated error: 1.6e-05 s status: 0040 unsync pll time constant: 4 precision: 1e-06 s frequency tolerance: 500 ppm
NTP operational (state 6) and the clock in a phase locked loop (pll)
pll offset: -0.074309 s pll frequency: -4.266 ppm maximum error: 0.027339 s estimated error: 0.027506 s status: 0001 pll pll time constant: 6 precision: 1e-06 s frequency tolerance: 500 ppm
root@sneezy:~# ntpq -np
remote refid st t when poll reach delay offset jitter ============================================================================== +192.168.1.2 194.100.100.141 3 u 35 64 377 1.299 -392.16 81.343 *193.180.251.38 192.36.144.22 2 u 33 64 377 187.899 -314.91 141.803 +82.118.208.35 213.203.238.82 3 u 36 64 377 154.986 -330.89 153.852
/etc/dhcp3/dhclient.conf /etc/ntp.conf.dhcp
/etc/ntp.conf server 192.168.1.2 restrict -4 default kod notrap nomodify nopeer noquery
/var/lib/ntp/ntp.drift
ntpq -np ntpdate 192.168.1.2
http://www.ntp.org/ntpfaq/NTP-s-trouble.htm
Windows Time
ms-sntp
net stop w32time w32tm /unregister w32tm /register net start w32time w32tm /resync
w32tm /config /manualpeerlist:"10.0.0.5,0x8 ntp.dnafinland.com,0xa" /syncfromflags:manual /update w32tm /stripchart /computer:time.windows.com /dataonly /samples:5
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\Config HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\w32time\Parameters\NtpServer
This seems to exist, but is not actually chosen?
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\DateTime\Servers
Android
platform-tools/adb shell
settings put global ntp_server 10.0.0.5 settings get global ntp_server
settings put global auto_time 0 settings put global auto_time 1 settings get global auto_time
GPS Time
A sync source are the 31 31 operational GPS satellites. They all have a cesium or rubidium atomic clock on board and provide. Not all GPS receivers export a PPS pulse per second which can be used by the GPSD to synchronize to NTPD, the ones that do can have different accuracy based on the gps chip and the mode used. The generic NMEA in one line ASCII is less accurate than any propitiatory binary protocol.
ntpd will use a pseudo-ip address 127.127.1.34 which is a local loopback address, as network socket to the gps driver (gpsd)
In 2010 I bought an BU-353 for 65 Euro's. It contains the popular SiRF_Star_III chip, but it has no pulse per second, so I can't use it as sync source.
./configure --prefix=/usr --disable-garmin --enable-pps-on-cts --disable-evermore --disable-navcom --disable-ashtech --disable-itrax --disable-earthmate --disable-tripmate --disable-fv18 --disable-tsip --disable-ntrip --disable-rtcm104
gpsd -nN -D 5 /dev/ttyUSB0 gpsd -nN /dev/ttyUSB0 gpsctl -b
gpsctl: /dev/ttyUSB0 identified as SiRF binary GSW3.2.4_3.1.00.12-SDK003P1.00a at 4800 gpsctl: /dev/ttyUSB0 identified as SiRF-II binary at 4800
http://wiki.openstreetmap.org/index.php/User:Dean_Earley/SiRF_Star_III http://www.usglobalsat.com/downloads/SiRF_Binary_Protocol.pdf http://www.mr-lee-catcam.de/BINARY/EM406a-datasheet.pdf
Mmmmh, this EM-406 looks like the stuff I saw when I disassembled the BU-353 (HA! those pins where really flimsy. That should teach me not to just pull them when drunk and trying to squeeze them back backwards =) ) ... do I have PPS on pin 6 EM-406a or a PPS-less model EM-406? and where does the PL-2303 RS232-USB converter come in to play??
http://www.usglobalsat.com/download/46/em406a_ug.pdf
Beitan BN-280
In 2019 I bough a Beitan BN-280 with a U-Blox M8N chip with a PPS pulse per second line. I used an arduino uno with SoftwareSerial on pin 10 and 11 to the gps chip. http://arduino.cc/en/Reference/SoftwareSerial
https://maker.pro/raspberry-pi/tutorial/how-to-use-a-gps-receiver-with-raspberry-pi-4
https://austinsnerdythings.com/2021/04/19/microsecond-accurate-ntp-with-a-raspberry-pi-and-pps-gps/
https://www.qso.com.ar/datasheets/Receptores%20GNSS-GPS/BN-280%20GPS%20Module%20Datasheet.pdf
1 | PPS | ||
2 | GND | ||
3 | TX | ||
4 | RX | ||
5 | VCC | 3 to 5V |
https://www.u-blox.com/en/product/neo-m8-series#tab-documentation-resources
Through U-Center and the NMEA set it can be tested and configured on windows. It's also possible to switch to U-Blox binary
GPS Commands
setSerialPort $PSRF100,0 $PSRF100,0,38400,8,1,0*0C
*switch to binary ?? $PASHQ,RI
Debug On $PSRF105,1*3E Debug Off $PSRF105,0*3F
Enable PowerSave $PSRF150,0,300,1000,1*10 Disable Trickle $PSRF150,0,1000,1000,0*23
Enable SBAS(WAAS/EGNOS) $PSRF151,01*0F Disable SBAS(WAAS/EGNOS) $PSRF151,00*0E
Roughtime
tlsdate was a parasitic method of retrieve an approximate initial time from tls servers. Since TLS 1.3, the server hello is optional and the server may not tell the time
A new initiative is Google Roughtime, with Cloudflare documenting how to use it in a blog and with a GOLANG code, (rust and java clients exist)
https://datatracker.ietf.org/doc/draft-ietf-ntp-roughtime/07/
git clone https://github.com/cloudflare/roughtime go get -u github.com/cloudflare/roughtime go install github.com/cloudflare/roughtime...
getroughtime -ping roughtime.cloudflare.com:2002 -pubkey gD63hSj3ScS+wuOeGrubXlq35N1c5Lby/S+T7MNTjxo= go run main.go -ping roughtime.cloudflare.com:2002 -pubkey gD63hSj3ScS+wuOeGrubXlq35N1c5Lby/S+T7MNTjxo=
dig TXT roughtime.cloudflare.com | grep -oP 'TXT\s"\K.*?(?=")'
go run main.go -ping roughtime.cloudflare.com:2002 -pubkey gD63hSj3ScS+wuOeGrubXlq35N1c5Lby/S+T7MNTjxo= go run main.go -ping roughtime.dnov.se:2002 -pubkey hlKAFAeU+xDZ1+9eVgrXel+m3sRiSlzoqCsqL9WoRB0= go run main.go -ping roughtime.int08h.com:2002 -pubkey AW5uAoTSTDfG5NfY1bTh08GUnOqlRb+HVhbJ3ODJvsE= go run main.go -ping roughtime.se:2002 -pubkey S3AzfZJ5CjSdkJ21ZJGbxqdYP/SoE8fXKY0+aicsehI= go run main.go -ping time.0xt.ca:2002 -pubkey iBVjxg/1j7y1+kQUTBYdTabxCppesU/07D4PMDJk2WA= go run main.go -ping roughtime.chainpoint.org:2002 -pubkey bbT+RPS7zKX6w71ssPibzmwWqU9ffRV5oj2OresSmhE= go run main.go -ping roughtime.sandbox.google.com:2002 -pubkey etPaaIxcBMY1oUeGpwvPMCJMwlRVNxv51KK/tktoJTQ= go run main.go -ping ticktock.mixmin.net:5333 -pubkey cj8GsiNlRkqiDElAeNMSBBMwrAl15hYPgX50+GWX/lA=
None of these server respond or use the correct version
PHP
It's probably easier to implement a time reporting function and tie it to a valid TLS certificate
<?php header('Content-Type:text/plain'); header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); echo gmdate("Y-m-d H:i:s"); ?>