I need to get the current time from one of internet time server in my desktop application. I suppose I need something like a request string and a regular expression to get time from any site that user wants (may be with several predefined sites).
Or may be there are some free libraries exist?
Thanks.
This is what the Network Time Protocol was built for. But it's probably something best left to your operating system, lest you end up with duelling applications using different, not-quite-synchronised servers.
See the headings in the link above for UNIX and Windows implementations.
There are free libraries and specifications for how to retrieve time, and the format in which you receive it (so REs are generally unnecessary). You choice depends on the level of precision/accuracy you want.
RFC 868 gives time to the second, which is entirely adequate for a lot of people's purposes. If it's good enough, it's a lot simpler to implement than the others listed below.
RFC 5905 defines the Network Time Protocol. As long as you only want to get the time, not provide it for anybody else, NTP is probably overkill though.
RFC 4330 defines SNTP (Simple NTP), which is a simplified version of NTP for computers that act as "leaf nodes" -- i.e., they retrieve time from elsewhere, but nothing else retrieves the time from them.
The NTP project has free NTP libraries for a number of systems.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With