Snippet: NTP Syncing (Windows/Linux)

Tux, the Linux penguin

English: M in blue square (similar to seen on )

A quick snippet for syncing your date and time via NTP. I have noticed that Windows and Linux do not follow the same convention by standard, and are always an hour out from each other, even though both claim to follow the same time zone. So, what I am having to do is sync via NTP each time I dual boot.

In Linux, this can be done using cron jobs or using the NTP daemon, but that does not do it frequently enough for my liking. So here is a bash snippet for it:

sudo service ntp stop
sudo ntpdate
sudo service ntp start

The first line stops the NTP daemon, since the ntpdate command does not like it when it is running (port in use). The second command uses a server in the selected list to sync with. The final line restarts the NTP daemon.

The Windows (Windows 7) equivalent is very similar. Like with linux, it has an in-built sync facility, but it again does not sync often enough for my liking. Like with the bash script, the commands must be run with elevated rights, so you must “Run as Administrator“, or run from an elevated rights command prompt, which you do as follows:

  1. Click Start, type “cmd” into the command window (do NOT use Windows+R)
  2. Hold down CTRL+SHIFT, then press ENTER
  3. You will be prompted (if you have UAC active), OK it and you will get a command prompt with “Administrator” in the title.

net stop "Windows Time"
net start "Windows Time"
w32tm /config /manualpeerlist:"" /syncfromflags:ALL /update
w32tm /resync

This code starts/restarts the Windows Time service then configures it with a pool of NTP servers, before asking the service to update itself and then resync. The resync action is what adjusts the time.