Link to home
Start Free TrialLog in
Avatar of PNRT
PNRT

asked on

VB.Net Getting time from government time server

Hi Experts.  Im writing a .Net4 VB program where accurate real time is important.   I can set Windows to update the time automatically from the internet but then I'm not sure if the workstation always has access to the internet.   I've tried pinging the time servers with no response so figure it would be easier to get the time from the servers myself.  Does anyone know how to get the time from time servers and then update the system clock.  That way if I cant get the time I can at least advise the user.  Thanks in advance.
Avatar of quizwedge
quizwedge
Flag of United States of America image

I think this is what you're looking for: http://www.codeproject.com/KB/vb/daytime.aspx
Avatar of Nasir Razzaq
>but then I'm not sure if the workstation always has access to the internet.
> so figure it would be easier to get the time from the servers myself.

How would you connect to the servers without the internet?
Avatar of PNRT
PNRT

ASKER

Thank you both for the replies.

Quizwedge - I tried this very project and couldnt get it to work

Codecruiser - My problem is that if I just allow the OS to update the time but the workstation cant get to the time server, the time may go out of sync and no one will know.   I thought that if I pinged the time servers that may give an indication that they were contactable and therefore were probably updating the time correctly, but got no response to the pings.  So I thought that getting the time directly would allow me to test whether it was working or not.and be able to advise the user

Thanks
Sorry, I had a family emergency so I haven't been able to test the project yet. Are you getting an error message? If so, what is the error message?
Avatar of PNRT

ASKER

Hi quizwedge, many thanks for the reply.  Im not getting any error message other than the "Cant connect to server"  Its trying a bunch of IP's tho and its quite dated.  Maybe thats the probelm.
I tried the second example from CodeCruiser, the one from dotnet-snippets.  It works great but its in C# which is beyond me Im afraid.  It has a VB module included but but the main program is C#.
Hope the family emergency wasnt to serious.
I dont see the C# code. Convert it here

http://converter.telerik.com/
Avatar of PNRT

ASKER

Sorry,  I didnt make myself clear - your second suggestion was a download of a VB class that I couldnt get working - but in the code was a link to the latest download.  This was the one that worked very well, but was in c#.   It included a VB module in it so that you could choose, but it was beyond me to change everythign to VB
Did you try the converter?
ASKER CERTIFIED SOLUTION
Avatar of quizwedge
quizwedge
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of PNRT

ASKER

With your changes, worked first time, many thanks for the help