The
HTTP RFC defines a Date header so pretty much all websites will return the current date/time in all http responses, so you can use that. Here's a sketch function to do that by making an HTTP HEAD request to google.com:
Code: Select allString getTime() {
WiFiClient client;
while (!!!client.connect("google.com", 80)) {
Serial.println("connection failed, retrying...");
}
client.print("HEAD / HTTP/1.1\r\n\r\n");
while(!!!client.available()) {
yield();
}
while(client.available()){
if (client.read() == '\n') {
if (client.read() == 'D') {
if (client.read() == 'a') {
if (client.read() == 't') {
if (client.read() == 'e') {
if (client.read() == ':') {
client.read();
String theDate = client.readStringUntil('\r');
client.stop();
return theDate;
}
}
}
}
}
}
}
}
That will return a String like "Thu, 15 Oct 2015 08:57:03 GMT"