Android Question Exact time from NTP server

Lakhtin_V

Active Member
Licensed User
Longtime User
On this forum I found one suitable option, but it does not work correctly. Returns the time zone instead of the real time.
SPSntp - getting time from the internet:
Dim sntp As SntpTime
Dim ticks As Long
sntp.NtpServerName = "0.de.pool.ntp.org"  ' only needed if you don't want to use the default server "0.us.pool.ntp.org"
sntp.TimeOut = 10000 ' only needed if you don't want to use the default timeout value of 30000 milliseconds (30 seconds)
ticks = sntp.getGmtNtpTime
Msgbox(ticks, "GMT Result in Ticks")
Msgbox(DateTime.Date(ticks), "GMT Date")
Msgbox(DateTime.Time(ticks), "GMT Time")
Msgbox(DateTime.Time(sntp.NtpTimeReference), "NtpTimeReference")
Msgbox(sntp.RoundTripTime, "RoundTripTime")
Maybe there are such solutions to get the exact time from the NTP server, with an accuracy of 1/100-1/1000 seconds? Using separate similar applications for Android, I noticed that there the difference between the exact NTP time and the system time changes very much in time. If you do a check every 5 seconds, the difference is 200-500 milliseconds, is this normal? Is it possible to get the exact time in milliseconds?
 

emexes

Expert
Licensed User
You can only get time to within the UDP round-trip travel time guaranteed, but more usually within half the difference of those travel times in each direction.

Round-trip time from here to your NTP server is tad over 300 ms. If I ping a local server, is 6 ms.

I'd like to think the local server is in the same city as me, but I suspect it might be in Sydney 900 km away. ? Actually, perhaps that is a good thing, because it implies that the travel time is equal both there and back, and thus the NTP synchronisation error probably < 1 ms.

1666768716805.png
 
Last edited:
Upvote 0
Top