Hi again,
i took this sample code as a base to build this small library.
The aim was to receive the actual time from the internet in ticks (timezone GMT). I skipped the string conversion to EST so only the tick values are returned.
Usage:
If an error occurrs during the time request (e.g. if a wrong server name was set), all time values return -1.
EDIT: Version 1.01 - added option to set an an own/preffered time server (default = "0.us.pool.ntp.org")
EDIT: Version 1.02 - the "android.permission.INTERNET" is now added automatically
EDIT: Version 1.03 - added option to set an own/preferred timeout value (default = 30000ms)
Caution: The way of handling network connections has changed since android 3 (you have to do all network connections within an non-gui background process) and this library does not support it directly. So if you wan't to use it with android 3 an above you have to handle the necessary threading on on your own.
Look at the attached sample "Sntp-Sample-V1.04".
specci48
i took this sample code as a base to build this small library.
The aim was to receive the actual time from the internet in ticks (timezone GMT). I skipped the string conversion to EST so only the tick values are returned.
Usage:
B4X:
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")
EDIT: Version 1.01 - added option to set an an own/preffered time server (default = "0.us.pool.ntp.org")
EDIT: Version 1.02 - the "android.permission.INTERNET" is now added automatically
EDIT: Version 1.03 - added option to set an own/preferred timeout value (default = 30000ms)
Caution: The way of handling network connections has changed since android 3 (you have to do all network connections within an non-gui background process) and this library does not support it directly. So if you wan't to use it with android 3 an above you have to handle the necessary threading on on your own.
Look at the attached sample "Sntp-Sample-V1.04".
specci48
Attachments
Last edited: