Tuesday 14 August 2012

Check current time over HTTP

Here's a way to check the current time using HTTP:

curl -I http://goo.gl | grep "Date: "

This will return a human readable line of text telling what the time is in GMT, in HTTP-Date format. Works on Linux, Cygwin and probably OSX. With a bit of work, this should be portable to Arduino :) [0]

The reason it works is because the web server you're polling (here, goo.gl, but you can use any server you like) will return the current time and date in its reply.

Thanks to Eddy Ververst for the idea.

[0] The fact that the HTTP-Date format is very permissible on what's allowed and what's not will make this a bit tricky to port to Arduino, but if you stick to a known server and check your results once in a while, you should be okay.