What is the command to update time and date from internet

What is the command to update time and date from Internet? Is there any application that allows me to do so from its user interface rather than from the shell?


Solution 1:

This is a nice little code I found to update your time in case you have issues with ntp:

sudo date -s "$(wget -qSO- --max-redirect=0 google.com 2>&1 | grep Date: | cut -d' ' -f5-8)Z"

Solution 2:

You can do so with e.g. sudo ntpdate time.nist.gov. Other servers include time.windows.com, etc.

http://www.pool.ntp.org/ lists time servers around the world.

Solution 3:

As of 2018 with a fresh installed Ubuntu 16.04 LTS, running sudo ntpdate time.nist.gov gives:

sudo: ntpdate: command not found

This is because (official source):

ntpdate is considered deprecated in favour of timedatectl and thereby no more installed by default.

Instead do this to force the sync to happen now:

sudo timedatectl set-ntp off
sudo timedatectl set-ntp on

In my case I was running a Ubuntu on a virtualbox and had saved the machine state so when I started the instance back up again it did not automatically sync the clock since there was no boot event to trigger the sync. So the time was still showing what it was the last time I was running the virtual box.

Solution 4:

Running this command in a terminal should do the trick

sudo dpkg-reconfigure tzdata

You can add extra time zones graphically, I think, by clicking on the clock and going through its options.