1

I have problem about getting online date from time.windows.com with C++. I just wanna get label from C++ with online time.

I got references but i dont know how to convert into C++ code. http://nickstips.wordpress.com/2010/02/12/c-get-nist-internet-time/ and http://tf.nist.gov/tf-cgi/servers.cgi

please help me

Davis
  • 127
  • 4
  • 14

3 Answers3

0

The answer might not be as simple as you imagined. There are basically three approaches you can take:

  1. Get the date/time from some NTP server. This approach basically means connecting to the server via Sockets (check this and this), or using an existing C++ library like net-snmp, snmp++ or this SNTP implementation

  2. Get the HTML page that displays this value and parse it for your value. It is best to use an existing HTML parser for this, like TinyXPath. I wouldn't go this way because it is unnecessarily complicated.

  3. Using a web service like like earthtools. You'll pass the necessary arguments in the URL and you receive the XML response which you can then parse.

I realize none of these solutions are as easy as you would want them to be, but when restricted to C++ they are all I can think of at this time.

Community
  • 1
  • 1
bosnjak
  • 8,424
  • 2
  • 21
  • 47
  • hmm im newbie here in C++ programming, i can not get it all sry....my C++ can not detect #include for socket things,how i can try this? – Davis Mar 15 '14 at 18:07
  • Windows socket programming is different than Linux. Search online for resources about c++ socket programming for Windows, there are plenty. However, I would suggest going with one of the libraries if you are a beginner. – bosnjak Mar 17 '14 at 09:28
0

rdate is a simple network protocol but you may find few servers providing this.

An alternative that is practical is to use the Date header from an HTTP server See section 14.18. Here is a write up for httpdate which uses this approach.

Finally, SNTP is not really that difficult to use. It is far simpler than full-blown NTP.

Community
  • 1
  • 1
patthoyts
  • 32,320
  • 3
  • 62
  • 93
0

If it helps someone out there, I have a personal method which really works for my date and time checking purposes(using C++ ), with NO need for too much accuracy (It is used to keeping track of roughly how many days an non-paying client has used my software for etc)

I have web server with a single-line PHP script (echo date("d-m-Y")), which I call using WinHTTP from my C++ code; parse the resulting string, and voila!

Cosmic OM...
  • 181
  • 4
  • 14