23-08-13, 04:34 AM
وهذه الدالة قمت باختصارها وتحسينها
كود :
Public Function GetInternetTime(ByVal host As String, Optional ByVal ToLocalTime As Boolean = False) As DateTime
Dim timeStr As String
Dim reader As New IO.StreamReader(New Net.Sockets.TcpClient(host, 13).GetStream)
Dim LastSysTime As DateTime
LastSysTime = DateTime.UtcNow()
timeStr = reader.ReadToEnd
reader.Close()
Dim year As Integer = CInt(timeStr.Substring(7, 2)) + 2000
Dim month As Integer = CInt(timeStr.Substring(10, 2))
Dim day As Integer = CInt(timeStr.Substring(13, 2))
Dim hour As Integer = CInt(timeStr.Substring(16, 2))
Dim minute As Integer = CInt(timeStr.Substring(19, 2))
Dim second As Integer = CInt(timeStr.Substring(22, 2))
If ToLocalTime Then
Return New DateTime(year, month, day, hour, minute, second).ToLocalTime
Else
Return New DateTime(year, month, day, hour, minute, second)
End If
End Function