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?
You can do so with e.g.
sudo ntpdate time.nist.gov. Other servers include
http://www.pool.ntp.org/ lists time servers around the world.
This is a nice little code I found to update your time in case you have issues with
sudo date -s "$(wget -qSO- --max-redirect=0 google.com 2>&1 | grep Date: | cut -d' ' -f5-8)Z"
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):
ntpdateis considered deprecated in favour of
timedatectland 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.
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.
It's very easy to set up from command line: https://help.ubuntu.com/lts/serverguide/NTP.html From that link:
Ubuntu comes with ntpdate as standard, and will run it once at boot time to set up your time according to Ubuntu's NTP server:
ntpdate -s ntp.ubuntu.com
Here's GUI example https://help.ubuntu.com/community/UbuntuTime#Time_Synchronization_using_NTP
Most here won't work, since ntp will override your settings within seconds.
You need to disable NTP first. On ubuntu it is done as:
# Disable ntp sudo timedatectl set-ntp 0
Then you can do:
# Set software clock sudo date --set="2018-04-01 22:22:22" # Sync with hardware clock sudo hwclock --systohc
dateFromServer=$(curl -v --silent https://google.com/ 2>&1 \ | grep Date | sed -e 's/< Date: //'); date +"%d%m%Y%H%M%S" -d "$dateFromServer"
date -s `curl -I 'https://startpage.com/' 2>/dev/null | grep -i '^date:' | sed 's/^[Dd]ate: //g'`
Is there any application that allows me to do so from its user interface rather than from the shell?
I'm using 17.10 and can go to Settings (from the upper-right menu in the UI) > Details > Date & Time. In my case, my system wasn't updating from the Internet even though "Automatic Date & Time" was set to "ON". I simply changed it to "OFF", waited a second, then changed it back to "ON". It picked up the current date and time and I was good to go.
You need to install the
ntp package. Date/Time settings are availble under system settings. Here's some more information.
Thanks to Twiglets [For AsusWRT/Merlin Routers]
Here is an alternative that DOES set the date !!! [-s option]. Prints out 'Date' it retrieves & the 'Date' that is set for comparison.
On AsusWRT / Merlin, the only thing that is odd is that the date retrieved is ".... GMT" and the date utility sets the correct time but changes it to "... DST" Environment has TZ set to "GMT"
datetext=$(curl -I 'https://220.127.116.11/' 2>/dev/null | grep "Date:" |sed 's/Date: [A-Z][a-z][a-z], //g'| sed 's/\r//') ; echo "Date Retrieved = $datetext" ; echo -n "Date set = " ; date -s "$datetext" -D'%d %b %Y %T %Z'