Need of time server services
I am trying to build a web application in ASP.NET and I need to retrieve time from a time server. Explaining the reasons why I need to do this is too long, however, I need, basically speaking, to connect to a time server (through web services hopefully) and retrieve that server current time.
NTP is a possible solution (question)
I know the existance of the NTP protocol and that it can be used for these purposes. However how is it possible to locate server addresses and use web services in order to get time?
Expecting web services
I, in fact, expect web services to be used for these reasons. However, by searching, I could not find any, also in the NTP official site.
How can I get time info from a server in my web app?
Thankyou
You don’t say how you want to choose which server’s time you want to get. I suppose that the reason you want to get the time from a remote server in the first place is that your code is running on a device without a local clock.
You can certainly make a client NTP request to some NTP server to get the time. Perhaps you would like to use
pool.ntp.orgas the NTP server.But if you prefer to use a web service, that’s fortunate because you can in fact get the current time from just about any web server in existence: they happen to emit it in the HTTP header of every response they send! Note the
Dateheader in this HTTP response from http://stackoverflow.com/ right now:So just choose a web server, make an HTTP request to it (for any page) and get the current time from the
Dateheader in the response. You can use theHEADmethod instead of theGETmethod as I did in thecurlexample because you don’t actually need the body of the response.