R
Rohan Danushka
Guest
Hi,
I'm try to get internet time and i got codes from previous MSDN support. but, when i try to run this code now my app going to break mode and there is 2 warnings. Please help me improve this code.
The Code:
Public Function GetNISTTime(ByVal host As String) As DateTime
If K9Core.CheckInternetConn = True Then
Dim timeStr As String
Try
Dim reader As New StreamReader(New TcpClient(host, 13).GetStream)
K9Core.LastSysTime = DateTime.UtcNow()
timeStr = reader.ReadToEnd()
reader.Close()
Catch ex As SocketException
InternetTime = ex.Message
Catch ex As Exception
InternetTime = ex.Message
End Try
Dim jd As Integer = Integer.Parse(timeStr.Substring(1, 5))
Dim yr As Integer = Integer.Parse(timeStr.Substring(7, 2))
Dim mo As Integer = Integer.Parse(timeStr.Substring(10, 2))
Dim dy As Integer = Integer.Parse(timeStr.Substring(13, 2))
Dim hr As Integer = Integer.Parse(timeStr.Substring(16, 2))
Dim mm As Integer = Integer.Parse(timeStr.Substring(19, 2))
Dim sc As Integer = Integer.Parse(timeStr.Substring(22, 2))
Dim Temp As Integer = CInt(AscW(timeStr(7)))
InternetTime = Format(Now, "yyyy/MM/dd h:mm tt")
Return New DateTime(yr + 2000, mo, dy, hr, mm, sc)
End If
End Function
Warnings:
Thank you...
RohanD
Continue reading...
I'm try to get internet time and i got codes from previous MSDN support. but, when i try to run this code now my app going to break mode and there is 2 warnings. Please help me improve this code.
The Code:
Public Function GetNISTTime(ByVal host As String) As DateTime
If K9Core.CheckInternetConn = True Then
Dim timeStr As String
Try
Dim reader As New StreamReader(New TcpClient(host, 13).GetStream)
K9Core.LastSysTime = DateTime.UtcNow()
timeStr = reader.ReadToEnd()
reader.Close()
Catch ex As SocketException
InternetTime = ex.Message
Catch ex As Exception
InternetTime = ex.Message
End Try
Dim jd As Integer = Integer.Parse(timeStr.Substring(1, 5))
Dim yr As Integer = Integer.Parse(timeStr.Substring(7, 2))
Dim mo As Integer = Integer.Parse(timeStr.Substring(10, 2))
Dim dy As Integer = Integer.Parse(timeStr.Substring(13, 2))
Dim hr As Integer = Integer.Parse(timeStr.Substring(16, 2))
Dim mm As Integer = Integer.Parse(timeStr.Substring(19, 2))
Dim sc As Integer = Integer.Parse(timeStr.Substring(22, 2))
Dim Temp As Integer = CInt(AscW(timeStr(7)))
InternetTime = Format(Now, "yyyy/MM/dd h:mm tt")
Return New DateTime(yr + 2000, mo, dy, hr, mm, sc)
End If
End Function
Warnings:
Thank you...
RohanD
Continue reading...