Hi,
I run jServer on vps.
I want to get current date and time of jServer from jRDC Client and convert to local date/time.
My code is as follow:
Is there alternative code?
Thanks.
I run jServer on vps.
I want to get current date and time of jServer from jRDC Client and convert to local date/time.
My code is as follow:
B4X:
Public Sub GetServerDateTime As String
Try
Dim j As HttpJob
Dim str1 as String
j.Initialize("", Me)
j.Download(Main.rdCheck) 'rdCheck is http://myip:port/test
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
str1 = j.GetString
If str1.Contains("successful") Then
Dim f,l As Int
f=mydb23.FindString(str1,"(")
l=mydb23.FindString(str1,")")
str1 =str1.SubString2(f+1,l)
DateTime.DateFormat = "MM/dd/yyyy HH:mm:ss"
Dim ServerTick As Long = DateTime.DateParse(str1)
j.Release
Dim addTimeZoneOffsetTicks As Long
addTimeZoneOffsetTicks = 7.5 * (60 * 60 * 1000)
DateTime.DateFormat = "MM/dd/yyy HH:mm:ss"
Dim ntz As Long
ntz=ServerTick+ addTimeZoneOffsetTicks
DateTime.DateFormat="dd-MMM-yyyy KK:mm:ss a"
str1 = DateTime.Date(ntz) 'ServerTick
End If
End If
j.Release
return str1
Catch
Msgbox (LastException.Message,"Error")
return str1
End Try
end Sub
Public Sub FindString(s As String, SearchFor As String) As Int
Try
Dim res As Int = -1
Dim n As Int = s.Length - 1
For i = 0 To n
res = s.IndexOf2(SearchFor, res + 1)
If res = -1 Then
Return -1
Else
i = n
End If
Next
Return res
Catch
Log(LastException)
Return res
End Try
End Sub
Is there alternative code?
Thanks.