R
Rohan Danushka
Guest
Hello,
please help,
Code Sample From: getting internet time
Questions:
1) I need to add 5 hours, 29 minutes and 59 seconds to internet time
2) Change windows 7/10 Date and Time with Internet Time
Why:
1) Hard to find correct time server for (UTC+05:30) Sri Jayawardenepura - Sri Lanka
2) If PC have Date Time issue need fix it
My Code:
Imports System.IO
Imports System.Net
Imports System.Net.Sockets
Imports System.Runtime.InteropServices
Public Class Form1
Public Shared LastSysTime As DateTime
Private Sub Label1_Click(sender As Object, e As EventArgs) Handles Label1.Click
Label1.Text = GetNISTTime("time.nist.gov").ToString
Label2.Text = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss tt")
End Sub
Public Function GetNISTTime(ByVal host As String) As DateTime
Dim timeStr As String
Try
Dim reader As New StreamReader(New TcpClient(host, 13).GetStream)
LastSysTime = DateTime.UtcNow()
timeStr = reader.ReadToEnd()
reader.Close()
Catch ex As SocketException
Label1.Text = ex.Message
Catch ex As Exception
Label1.Text = 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)))
Return New DateTime(yr + 2000, mo, dy, hr, mm, sc)
End Function
End Class
Preview:
I'm very gladful for your help with this... Thank You
RohanD
Continue reading...
please help,
Code Sample From: getting internet time
Questions:
1) I need to add 5 hours, 29 minutes and 59 seconds to internet time
2) Change windows 7/10 Date and Time with Internet Time
Why:
1) Hard to find correct time server for (UTC+05:30) Sri Jayawardenepura - Sri Lanka
2) If PC have Date Time issue need fix it
My Code:
Imports System.IO
Imports System.Net
Imports System.Net.Sockets
Imports System.Runtime.InteropServices
Public Class Form1
Public Shared LastSysTime As DateTime
Private Sub Label1_Click(sender As Object, e As EventArgs) Handles Label1.Click
Label1.Text = GetNISTTime("time.nist.gov").ToString
Label2.Text = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss tt")
End Sub
Public Function GetNISTTime(ByVal host As String) As DateTime
Dim timeStr As String
Try
Dim reader As New StreamReader(New TcpClient(host, 13).GetStream)
LastSysTime = DateTime.UtcNow()
timeStr = reader.ReadToEnd()
reader.Close()
Catch ex As SocketException
Label1.Text = ex.Message
Catch ex As Exception
Label1.Text = 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)))
Return New DateTime(yr + 2000, mo, dy, hr, mm, sc)
End Function
End Class
Preview:
I'm very gladful for your help with this... Thank You
RohanD
Continue reading...