B4A Library [B4X] SNTP class

Erel

Administrator
Staff member
Licensed User
This class sends a request to a SNTP server (time server) and finds the offset between the local clock and the remote clock.

Usage example:
B4X:
SntpClient.Initialize 'global variable. Put in Starter service in B4A
Wait For(SntpClient.UpdateOffsets) Complete (Result As Boolean)
If Result Then
   Log("Time updated successfully.")
   Log($"$Time{SntpClient.Now}"$)
End If
You only need to calculate the offsets once. Once calculated you can call Sntp.Now to get the current time.

This class will work in B4A, B4J and B4i.

Depends on: Network and RandomAccessFile.

It is based on Android source code - Apache license 2.0.
 

Attachments

Last edited:

Filippo

Expert
Licensed User
Thank you! :)
That was faster than the police allowed. :D
 

Filippo

Expert
Licensed User
I have done a few tests with this module and the library.
There are always different results between the two methods, and now I do not know what should be the right one. :(

b4a-SNTP.JPG
 

Attachments

Filippo

Expert
Licensed User
But I think your routine is better than the library, it takes less time compared to the library. ;)
And besides, I do not need those two objects anymore.
B4X:
    'Objekte für die Atomzeit
    Private Thread1 As Thread
    Private Thread2 As Thread
 
Top