Sync Windows Date

2006-10-20 23:15 - Tech

If you double click on the time displayed in the system tray on a windows system, you'll get the "Date and Time Properties" window. It lets you set the current date and time, but I use it most often for a quick calendar of the current month (or sometimes future/past months as well). There's an interesting tab labeled "internet time" there, too.

Thing is, that tab has never worked for me. On Linux systems, it's almost too easy to run ntpdate, but Windows makes it tougher. A while back, I had found a perl script that would set your system clock based off of an HTTP response. What a nifty idea!

According to the RFC defining HTTP, "Origin servers MUST include a Date header field in all responses, except in these cases," and it goes on to list cases that rarely happen. So, I decided that would be an easy way to fix up the clock on my Windows desktop.

I couldn't find that script, but ended up crafting a tiny one-liner to do it anyway. This, though, is a bash command, so you'd need something like cygwin, which I can't live without anyways. It would best be put into a shell script for frequent use, but it's also pretty easy to just copy/paste:

date -s "`wget -SO /dev/null http://HTTP_HOST_HERE/ 2>&1 | sed -n '/Date:/{s/.*Date: //;p}'`"

Make sure you put a valid host in there. I used the linux server sitting on my local network, because this method of course does not compensate for transmission delays. This is probably not terribly portable code, either, but who doesn't run GNU date and wget?


No comments!

Post a comment:

  If you do not have an account to log in to yet, register your own account. You will not enter any personal info and need not supply an email address.

You may use Markdown syntax in the comment, but no HTML. Hints:

  • An empty line between text will create a paragraph boundary.
  • Use angle braces around a plain URL to auto-link it: <>.
  • Use this format to create a link with different text showing: [An Example](
  • Use backticks (``), not leading spaces to enclose a code block.

If you are attempting to contact me, ask me a question, etc, please send me a message through the contact form rather than posting a comment here. Thank you. (If you post a comment anyway when it should be a message to me, I'll probably just delete your comment. I don't like clutter.)