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?

    Can you identify which Ubuntu version you are using?

    Do you need extremely accurate time? (If so, you need to familiarize yourself with **ntpq** and choose time servers). If you just want your time to be (approx.) correct, then try: **System Settings >> Time & Date**, and check that '_Set the time_' is set to '_Automatically from the Internet_'.

    If you want constantly extremely accurate, install `ntpd`. This is a small process that runs in the background and adjusts time constantly instead of bursts/jumps, but it will take up a bit of your resources.

    Worth noting that this changed as of 2018, and the top answers are no longer correct for recent versions of Ubuntu. You will likely need this answer: https://askubuntu.com/a/998449/53783

    `sudo ntpd` should be enough

    This question is of critical importance nowadays. Lately it's become very tricky : some PCs use chrony or ntpd, they always find a reason NOT to update the time (clock is *too wrong*, win dual-boot-related issues, ntp may also refuse to trust clock sources that don't have internet). Moreover, if you have a PC with internet, but a wrong clock, as now browsers and websites force you to use HTTPS, it will block as your clock is wrong, and you can't even google how to fix it! It would be nice if there was an answer that addresses all cases. "Set the clock by hand" is the most reliable one now...

  • Anonymous

    Anonymous Correct answer

    9 years ago

    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.

    I'm getting an error `the NTP socket is in use, exiting`

    @friederbluemle As said in this answer, you have to stop ntp service `sudo service ntp stop`. Then you can use the command suggested in the answer and finally you can restart the service with `sudo service ntp start`

    This works, but it doesn't update the clock in the taskbar automatically.

    I get a "ntpdate[15806]: no server suitable for synchronization found" error. The second answer below using the google.com works better

    ntpdate: command not found

    if you want to use `nptdate`, and it's not found, then: `sudo apt install ntpdate`; note that it's not installed by default anymore, and may no longer be the preferred solution with latest versions of ubuntu; see https://help.ubuntu.com/community/UbuntuTime and see also https://askubuntu.com/questions/254826/how-to-force-a-clock-update-using-ntp for more options (as well as other answers to this question)

    ` 6 Nov 19:55:16 ntpdate[8504]: no server suitable for synchronization found`

  • 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"

    Nice solution !

    Very Nice, worked for me.

    This should be the accepted answer!

    This snippet made its way to my arsenal ! ;)

    Crazy, but it works!

    for me too this is the solution

    Works, but I have one problem. The command sets the clock to GMT, not the local time. Any workaround for this?

    This is good, but it usually will be between 8 and 50 ms behind since it doesn't synchronize per se.

    @gksamarth this command did set the correct timezone for me (I'm currently GMT+2)

    It works for me, anyone knows an equivalent command without sudo? I would like to put it in the .bashrc file to be executed at every terminal I open

    I like this answer because it is similar to one I had to employ on a STB which had WebKit but not NTP! And we actually used XMLHttpRequest instead of wget. And we had to build a JS extension into the WebKit port so that it could set the time from the time we parsed from the HTTP header. It had to be kinda accurate and that's what we got. I tried the wget version just now but the wget I have is not configured for https so it didn't work.

  • 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.

    I just upgraded to bionic and noticed that ntpdate wasn't working anymore, and timedatectl worked for me.

    It worked for me too, on Ubuntu 18.04.

    If the time doesn't change, check your timezone with just `timedatectl`. If it's wrong, see the `--help` section for the command on how to change it.

    Nice catch for the Virtual Box. Saved a lot of debugging headache!

  • 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.

    Timezones are not really the same as (accurate) time. But, it also not very clear what **Vikramjeet** was asking either.

    What is the command to update time and date from Internet is the question, sudo dpkg-reconfigure tzdata is the answer, so what gives? the comment about the timezones, is related to the only thing i know to be possible graphically

    I assumed that by **graphically** they meant a graphical (or 'GUI') method, and NOT geographic (or worldwide).

    so did i, i am not aware of a way to update the date and time via the net **graphically**, so i use the terminal, what i **do** know how to do **graphically** is set up time zones, the part about time zones was my two cents on what can be done to affect the time in a **graphical** manner, as far as i knew, am i understood now?

  • 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

    Please do not use links to other sites. When they disappear so does the information you posted. Prevent 'link rot' from happening by answering with the content of the link (and give credit where credit is due).

  • 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'`

    The standard way of setting the date and time by connecting with time servers via ntp. Why are you using https connections to do this?

    // , Sometimes it's nice to have an alternative to the standard way, I guess.

    My ISP was blocking my NTP server

  • 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.

    The link is dead... As said by Rinzwind "Please do not use links to other sites. When they disappear so does the information you posted. Prevent 'link rot' from happening by answering with the content of the link (and give credit where credit is due)." Thanks

  • 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 '' 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'

License under CC-BY-SA with attribution

Content dated before 6/26/2020 9:53 AM

Tags used