How do I set time and date from the Internet?Trying to set date on a Linux based machine from another...

Python 3 - simple temperature program

How does the reduce() method work in Java 8?

To kill a cuckoo

What is a common way to tell if an academic is "above average," or outstanding in their field? Is their h-index (Hirsh index) one of them?

Why aren't nationalizations in Russia described as socialist?

Is the book wrong about the Nyquist Sampling Criterion?

How to pass hash as password to ssh server

Why didn't this character get a funeral at the end of Avengers: Endgame?

Is there an age requirement to play in Adventurers League?

Constitutional limitation of criminalizing behavior in US law?

Copy previous line to current line from text file

Is there a word for food that's gone 'bad', but is still edible?

Why is my arithmetic with a long long int behaving this way?

What do I do if my advisor made a mistake?

Are the Night's Watch still required?

Is there precedent or are there procedures for a US president refusing to concede to an electoral defeat?

Why would a military not separate its forces into different branches?

How long would it take for people to notice a mass disappearance?

How should I tell my manager I'm not paying for an optional after work event I'm not going to?

Formatting Datetime.now()

What are the advantages of luxury car brands like Acura/Lexus over their sibling non-luxury brands Honda/Toyota?

Mug and wireframe entirely disappeared

Why do these characters still seem to be the same age after the events of Endgame?

Handling Null values (and equivalents) routinely in Python



How do I set time and date from the Internet?


Trying to set date on a Linux based machine from another machineTrying to set date on a Linux based machine from another machineHow to force the time and date settings to refresh from the internet?What else apart from /etc/localtime and $TZ affects `date`?Automatically synchronization between system time and hardware clock timeHow to set time in nanoseconds?Getting the date from a ssh clienthow does the gnu coreutils `date` work?how to set the date & time PermanentlyChrony client do not change system and hardware dateSet date on embedded linux with limited busybox (no ntp)






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







33















How do I retrieve the date from the Internet and set my computer's clock, from the command line?










share|improve this question




















  • 2





    I do not understand downvotes. Simple questions are what make a community powerful. For example see this

    – Mohsen
    Jun 12 '13 at 6:35








  • 3





    When I hover above a question's down arrow with my mouse I see: "This question does not show any research effort; it is unclear or not useful". I would be tempted to downvote your question based on the first (no indication of what you found), the second (no indication on what specific platform you are working on, and why this has to be commandline (instead of the usual time daemon)) and the third (most *nix users will have some time daemon installed by default).

    – Anthon
    Jun 12 '13 at 7:09













  • +1 I do not understand the downvotes either, simply because this is something which has bugged me many times before, and it seems impossible to find anything concise and useful about this specific theme.

    – l0b0
    Jun 12 '13 at 7:52











  • @Mohsen I didn't downvote but the difference to the question you linked is that there is no switch in ruby while you can set directly the date via date -s (as shown in the manpage), or use any of the commands described below...

    – Ulrich Dangel
    Jun 12 '13 at 8:33






  • 1





    @Anthon I disagree: that question is about a small device with BusyBox, which makes the generic advice “use NTP” not necessarily applicable

    – Gilles
    Jun 12 '13 at 22:55


















33















How do I retrieve the date from the Internet and set my computer's clock, from the command line?










share|improve this question




















  • 2





    I do not understand downvotes. Simple questions are what make a community powerful. For example see this

    – Mohsen
    Jun 12 '13 at 6:35








  • 3





    When I hover above a question's down arrow with my mouse I see: "This question does not show any research effort; it is unclear or not useful". I would be tempted to downvote your question based on the first (no indication of what you found), the second (no indication on what specific platform you are working on, and why this has to be commandline (instead of the usual time daemon)) and the third (most *nix users will have some time daemon installed by default).

    – Anthon
    Jun 12 '13 at 7:09













  • +1 I do not understand the downvotes either, simply because this is something which has bugged me many times before, and it seems impossible to find anything concise and useful about this specific theme.

    – l0b0
    Jun 12 '13 at 7:52











  • @Mohsen I didn't downvote but the difference to the question you linked is that there is no switch in ruby while you can set directly the date via date -s (as shown in the manpage), or use any of the commands described below...

    – Ulrich Dangel
    Jun 12 '13 at 8:33






  • 1





    @Anthon I disagree: that question is about a small device with BusyBox, which makes the generic advice “use NTP” not necessarily applicable

    – Gilles
    Jun 12 '13 at 22:55














33












33








33


14






How do I retrieve the date from the Internet and set my computer's clock, from the command line?










share|improve this question
















How do I retrieve the date from the Internet and set my computer's clock, from the command line?







command-line date remote clock






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jun 12 '13 at 22:57









Gilles

551k13211241637




551k13211241637










asked Jun 12 '13 at 5:40









MohsenMohsen

90021527




90021527








  • 2





    I do not understand downvotes. Simple questions are what make a community powerful. For example see this

    – Mohsen
    Jun 12 '13 at 6:35








  • 3





    When I hover above a question's down arrow with my mouse I see: "This question does not show any research effort; it is unclear or not useful". I would be tempted to downvote your question based on the first (no indication of what you found), the second (no indication on what specific platform you are working on, and why this has to be commandline (instead of the usual time daemon)) and the third (most *nix users will have some time daemon installed by default).

    – Anthon
    Jun 12 '13 at 7:09













  • +1 I do not understand the downvotes either, simply because this is something which has bugged me many times before, and it seems impossible to find anything concise and useful about this specific theme.

    – l0b0
    Jun 12 '13 at 7:52











  • @Mohsen I didn't downvote but the difference to the question you linked is that there is no switch in ruby while you can set directly the date via date -s (as shown in the manpage), or use any of the commands described below...

    – Ulrich Dangel
    Jun 12 '13 at 8:33






  • 1





    @Anthon I disagree: that question is about a small device with BusyBox, which makes the generic advice “use NTP” not necessarily applicable

    – Gilles
    Jun 12 '13 at 22:55














  • 2





    I do not understand downvotes. Simple questions are what make a community powerful. For example see this

    – Mohsen
    Jun 12 '13 at 6:35








  • 3





    When I hover above a question's down arrow with my mouse I see: "This question does not show any research effort; it is unclear or not useful". I would be tempted to downvote your question based on the first (no indication of what you found), the second (no indication on what specific platform you are working on, and why this has to be commandline (instead of the usual time daemon)) and the third (most *nix users will have some time daemon installed by default).

    – Anthon
    Jun 12 '13 at 7:09













  • +1 I do not understand the downvotes either, simply because this is something which has bugged me many times before, and it seems impossible to find anything concise and useful about this specific theme.

    – l0b0
    Jun 12 '13 at 7:52











  • @Mohsen I didn't downvote but the difference to the question you linked is that there is no switch in ruby while you can set directly the date via date -s (as shown in the manpage), or use any of the commands described below...

    – Ulrich Dangel
    Jun 12 '13 at 8:33






  • 1





    @Anthon I disagree: that question is about a small device with BusyBox, which makes the generic advice “use NTP” not necessarily applicable

    – Gilles
    Jun 12 '13 at 22:55








2




2





I do not understand downvotes. Simple questions are what make a community powerful. For example see this

– Mohsen
Jun 12 '13 at 6:35







I do not understand downvotes. Simple questions are what make a community powerful. For example see this

– Mohsen
Jun 12 '13 at 6:35






3




3





When I hover above a question's down arrow with my mouse I see: "This question does not show any research effort; it is unclear or not useful". I would be tempted to downvote your question based on the first (no indication of what you found), the second (no indication on what specific platform you are working on, and why this has to be commandline (instead of the usual time daemon)) and the third (most *nix users will have some time daemon installed by default).

– Anthon
Jun 12 '13 at 7:09







When I hover above a question's down arrow with my mouse I see: "This question does not show any research effort; it is unclear or not useful". I would be tempted to downvote your question based on the first (no indication of what you found), the second (no indication on what specific platform you are working on, and why this has to be commandline (instead of the usual time daemon)) and the third (most *nix users will have some time daemon installed by default).

– Anthon
Jun 12 '13 at 7:09















+1 I do not understand the downvotes either, simply because this is something which has bugged me many times before, and it seems impossible to find anything concise and useful about this specific theme.

– l0b0
Jun 12 '13 at 7:52





+1 I do not understand the downvotes either, simply because this is something which has bugged me many times before, and it seems impossible to find anything concise and useful about this specific theme.

– l0b0
Jun 12 '13 at 7:52













@Mohsen I didn't downvote but the difference to the question you linked is that there is no switch in ruby while you can set directly the date via date -s (as shown in the manpage), or use any of the commands described below...

– Ulrich Dangel
Jun 12 '13 at 8:33





@Mohsen I didn't downvote but the difference to the question you linked is that there is no switch in ruby while you can set directly the date via date -s (as shown in the manpage), or use any of the commands described below...

– Ulrich Dangel
Jun 12 '13 at 8:33




1




1





@Anthon I disagree: that question is about a small device with BusyBox, which makes the generic advice “use NTP” not necessarily applicable

– Gilles
Jun 12 '13 at 22:55





@Anthon I disagree: that question is about a small device with BusyBox, which makes the generic advice “use NTP” not necessarily applicable

– Gilles
Jun 12 '13 at 22:55










10 Answers
10






active

oldest

votes


















27














You can use :



sudo dpkg-reconfigure tzdata


for configuring your timezone .



For updating time and date from internet use the following :



Install



If ntpd is not installed use any one of the following command to install ntpd:





  • For RPM based:



    yum install ntp 



  • For Debian based:



    sudo apt-get install ntp



Configuration



You should at least set following parameter in /etc/ntp.conf config file:
server



For example, open /etc/ntp.conf file using vi text editor:



  # vi /etc/ntp.conf


Locate server parameter and set it as follows:



  server pool.ntp.org


Save the file and restart the ntpd service:



  # /etc/init.d/ntpd start


You can synchronize the system clock to an NTP server immediately with following command:



  # ntpdate pool.ntp.org


*For setting the time and date manually use the following syntax:



 date --set="STRING"


For example, set new data to 2 Oct 2006 18:00:00, type the following command as root user:



# date -s "2 OCT 2006 18:00:00"


OR



# date --set="2 OCT 2006 18:00:00"


You can also simplify format using following syntax:



# date +%Y%m%d -s "20081128"


To set time use the following syntax:



# date +%T -s "10:13:13"


Where,



10: Hour (hh)
13: Minute (mm)
13: Second (ss)



Use %p locale’s equivalent of either AM or PM, enter:



# date +%T%p -s "6:10:30AM"

# date +%T%p -s "12:10:30PM"





share|improve this answer


























  • Although the date information seems all valid, it does not take the requirement from the internet from the title of the OP into account anywhere.

    – Anthon
    Jun 12 '13 at 7:03











  • I believe that tzdata (time zone data) package synchronizes the data from internet only. Correct me if I am wrong .

    – tusharmakkar08
    Jun 12 '13 at 7:26






  • 3





    tzdata is information about timezones and daylight saving time (start, end, epoch) not the actual date and time. Of course that is handy to know how to get to your local time based on knowledge of your timezone and a UTC time, but you still need to retrieve the latter from the internet.

    – Anthon
    Jun 12 '13 at 7:42













  • You are wrong. time zone data has to be updated (as there are changes happening all the time) BUT it does not update itself automatically from the internet NOR does it set the time from the internet.

    – Ulrich Dangel
    Jun 12 '13 at 8:32











  • @Anthon : I have edited my answer correspondingly.Thank You.

    – tusharmakkar08
    Jun 12 '13 at 9:43



















20














A small code I found to update your time in case you don't want to install anything just to update the date. :)



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





share|improve this answer



















  • 1





    I use google.in to get the current time for my timezone (INDIA).

    – Dilawar
    Jul 25 '18 at 12:35











  • Note the trailing Z which indicates that the time is given in zulu time zone, so no special timezone manipulation should be needed if the computer timezone is set correctly.

    – user202729
    Sep 6 '18 at 13:13



















9














I use this:



sudo ntpd -qg; sudo hwclock -w


first tell ntpd to just set the time and stop after that with -q. Also, in case a your clock has a big error we need to tell ntpd to also adjust in that case with -g. Finally write the clock to hardware to preserve the changes when rebooting with hwclock -w (-w for setting hardwareclock to current system time, there is a difference).






share|improve this answer



















  • 1





    i tend to do this with a "&&" instead of the semicolon so that if the first command should fail (e.g. network connectivity down) the second command is short-circuited

    – Theophrastus
    Sep 19 '15 at 20:06



















7














Use ntpdate, ntpd, or Chrony to connect to a NTP server.






share|improve this answer































    5














    Some distributions are shipping rdate for that purpose. Basic usage:



    # just query
    bash-4.2$ rdate pool.ntp.org
    rdate: [pool.ntp.org] Wed Jun 12 11:05:40 2013

    # set system time
    bash-4.2$ rdate -s pool.ntp.org





    share|improve this answer
























    • Way better and easier than ntp

      – andrewtweber
      Mar 30 '16 at 18:39











    • pool.ntp.org now refuses connections from rdate. time.nist.gov works. Also once you have set the system time, you should set the hardware clock as well by running hwclock -w to set it to the system time. You can then verify it is correct by running hwclock -r

      – MatthewLee
      Jul 14 '17 at 14:53



















    4














    After some research, I ended up with this. I also applied it to my own server:



    sudo apt-get install ntp
    sudo dpkg-reconfigure ntp
    ntpq -p


    If the last command shows a valid list of servers, you are good to go. The command will run a quite complex set of algorithms which will iterate your clock drift, among other things, and compensate for them. You will end up with a pretty accurate clock even if you lose the connection to the NTP servers. However, the command does require a few minutes to get started.



    Source: here and here.






    share|improve this answer































      0














      To find "peers" (hosts you can query) you can use ntpq -p.



      If you already have an NTP service running you have to stop it before manually updating, for example using sudo service ntp stop.



      Now you can query a peer, for example using sudo ntpdate "peer".






      share|improve this answer































        0














        Using rdate tool as suggested in manatwork's answer, but with SNTP protocol -n and IPv4 -4 options on:



        # just print synced time, not set
        rdate -n -4 -p time-a.nist.gov

        # print and set synced time
        sudo rdate -n -4 time-a.nist.gov


        The tool may be installed on Debian this way:



        sudo apt-get install rdate





        share|improve this answer































          0














          In addition to Tushar's reply, I also had to do apt-get install ntpdate on my Ubuntu 14.04.



          Posting as answer because reputation does not suffice for commenting.






          share|improve this answer

































            0














            I also was looking for a non ntp/ntpd way of resetting clock periodically. I liked the google.com header parsing but found it did not work on ubuntu. I think this will also work on a Raspberry Pi.



            sudo date +"%d %b %Y %T %Z" -s "$(wget -qSO- --max-redirect=0 http://google.com 2>&1 | grep '^  Date:' | cut -d' ' -f 5-)"





            share|improve this answer








            New contributor




            Ron B is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.





















              Your Answer








              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "106"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: false,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f79112%2fhow-do-i-set-time-and-date-from-the-internet%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              10 Answers
              10






              active

              oldest

              votes








              10 Answers
              10






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              27














              You can use :



              sudo dpkg-reconfigure tzdata


              for configuring your timezone .



              For updating time and date from internet use the following :



              Install



              If ntpd is not installed use any one of the following command to install ntpd:





              • For RPM based:



                yum install ntp 



              • For Debian based:



                sudo apt-get install ntp



              Configuration



              You should at least set following parameter in /etc/ntp.conf config file:
              server



              For example, open /etc/ntp.conf file using vi text editor:



                # vi /etc/ntp.conf


              Locate server parameter and set it as follows:



                server pool.ntp.org


              Save the file and restart the ntpd service:



                # /etc/init.d/ntpd start


              You can synchronize the system clock to an NTP server immediately with following command:



                # ntpdate pool.ntp.org


              *For setting the time and date manually use the following syntax:



               date --set="STRING"


              For example, set new data to 2 Oct 2006 18:00:00, type the following command as root user:



              # date -s "2 OCT 2006 18:00:00"


              OR



              # date --set="2 OCT 2006 18:00:00"


              You can also simplify format using following syntax:



              # date +%Y%m%d -s "20081128"


              To set time use the following syntax:



              # date +%T -s "10:13:13"


              Where,



              10: Hour (hh)
              13: Minute (mm)
              13: Second (ss)



              Use %p locale’s equivalent of either AM or PM, enter:



              # date +%T%p -s "6:10:30AM"

              # date +%T%p -s "12:10:30PM"





              share|improve this answer


























              • Although the date information seems all valid, it does not take the requirement from the internet from the title of the OP into account anywhere.

                – Anthon
                Jun 12 '13 at 7:03











              • I believe that tzdata (time zone data) package synchronizes the data from internet only. Correct me if I am wrong .

                – tusharmakkar08
                Jun 12 '13 at 7:26






              • 3





                tzdata is information about timezones and daylight saving time (start, end, epoch) not the actual date and time. Of course that is handy to know how to get to your local time based on knowledge of your timezone and a UTC time, but you still need to retrieve the latter from the internet.

                – Anthon
                Jun 12 '13 at 7:42













              • You are wrong. time zone data has to be updated (as there are changes happening all the time) BUT it does not update itself automatically from the internet NOR does it set the time from the internet.

                – Ulrich Dangel
                Jun 12 '13 at 8:32











              • @Anthon : I have edited my answer correspondingly.Thank You.

                – tusharmakkar08
                Jun 12 '13 at 9:43
















              27














              You can use :



              sudo dpkg-reconfigure tzdata


              for configuring your timezone .



              For updating time and date from internet use the following :



              Install



              If ntpd is not installed use any one of the following command to install ntpd:





              • For RPM based:



                yum install ntp 



              • For Debian based:



                sudo apt-get install ntp



              Configuration



              You should at least set following parameter in /etc/ntp.conf config file:
              server



              For example, open /etc/ntp.conf file using vi text editor:



                # vi /etc/ntp.conf


              Locate server parameter and set it as follows:



                server pool.ntp.org


              Save the file and restart the ntpd service:



                # /etc/init.d/ntpd start


              You can synchronize the system clock to an NTP server immediately with following command:



                # ntpdate pool.ntp.org


              *For setting the time and date manually use the following syntax:



               date --set="STRING"


              For example, set new data to 2 Oct 2006 18:00:00, type the following command as root user:



              # date -s "2 OCT 2006 18:00:00"


              OR



              # date --set="2 OCT 2006 18:00:00"


              You can also simplify format using following syntax:



              # date +%Y%m%d -s "20081128"


              To set time use the following syntax:



              # date +%T -s "10:13:13"


              Where,



              10: Hour (hh)
              13: Minute (mm)
              13: Second (ss)



              Use %p locale’s equivalent of either AM or PM, enter:



              # date +%T%p -s "6:10:30AM"

              # date +%T%p -s "12:10:30PM"





              share|improve this answer


























              • Although the date information seems all valid, it does not take the requirement from the internet from the title of the OP into account anywhere.

                – Anthon
                Jun 12 '13 at 7:03











              • I believe that tzdata (time zone data) package synchronizes the data from internet only. Correct me if I am wrong .

                – tusharmakkar08
                Jun 12 '13 at 7:26






              • 3





                tzdata is information about timezones and daylight saving time (start, end, epoch) not the actual date and time. Of course that is handy to know how to get to your local time based on knowledge of your timezone and a UTC time, but you still need to retrieve the latter from the internet.

                – Anthon
                Jun 12 '13 at 7:42













              • You are wrong. time zone data has to be updated (as there are changes happening all the time) BUT it does not update itself automatically from the internet NOR does it set the time from the internet.

                – Ulrich Dangel
                Jun 12 '13 at 8:32











              • @Anthon : I have edited my answer correspondingly.Thank You.

                – tusharmakkar08
                Jun 12 '13 at 9:43














              27












              27








              27







              You can use :



              sudo dpkg-reconfigure tzdata


              for configuring your timezone .



              For updating time and date from internet use the following :



              Install



              If ntpd is not installed use any one of the following command to install ntpd:





              • For RPM based:



                yum install ntp 



              • For Debian based:



                sudo apt-get install ntp



              Configuration



              You should at least set following parameter in /etc/ntp.conf config file:
              server



              For example, open /etc/ntp.conf file using vi text editor:



                # vi /etc/ntp.conf


              Locate server parameter and set it as follows:



                server pool.ntp.org


              Save the file and restart the ntpd service:



                # /etc/init.d/ntpd start


              You can synchronize the system clock to an NTP server immediately with following command:



                # ntpdate pool.ntp.org


              *For setting the time and date manually use the following syntax:



               date --set="STRING"


              For example, set new data to 2 Oct 2006 18:00:00, type the following command as root user:



              # date -s "2 OCT 2006 18:00:00"


              OR



              # date --set="2 OCT 2006 18:00:00"


              You can also simplify format using following syntax:



              # date +%Y%m%d -s "20081128"


              To set time use the following syntax:



              # date +%T -s "10:13:13"


              Where,



              10: Hour (hh)
              13: Minute (mm)
              13: Second (ss)



              Use %p locale’s equivalent of either AM or PM, enter:



              # date +%T%p -s "6:10:30AM"

              # date +%T%p -s "12:10:30PM"





              share|improve this answer















              You can use :



              sudo dpkg-reconfigure tzdata


              for configuring your timezone .



              For updating time and date from internet use the following :



              Install



              If ntpd is not installed use any one of the following command to install ntpd:





              • For RPM based:



                yum install ntp 



              • For Debian based:



                sudo apt-get install ntp



              Configuration



              You should at least set following parameter in /etc/ntp.conf config file:
              server



              For example, open /etc/ntp.conf file using vi text editor:



                # vi /etc/ntp.conf


              Locate server parameter and set it as follows:



                server pool.ntp.org


              Save the file and restart the ntpd service:



                # /etc/init.d/ntpd start


              You can synchronize the system clock to an NTP server immediately with following command:



                # ntpdate pool.ntp.org


              *For setting the time and date manually use the following syntax:



               date --set="STRING"


              For example, set new data to 2 Oct 2006 18:00:00, type the following command as root user:



              # date -s "2 OCT 2006 18:00:00"


              OR



              # date --set="2 OCT 2006 18:00:00"


              You can also simplify format using following syntax:



              # date +%Y%m%d -s "20081128"


              To set time use the following syntax:



              # date +%T -s "10:13:13"


              Where,



              10: Hour (hh)
              13: Minute (mm)
              13: Second (ss)



              Use %p locale’s equivalent of either AM or PM, enter:



              # date +%T%p -s "6:10:30AM"

              # date +%T%p -s "12:10:30PM"






              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Aug 3 '16 at 8:59









              Kusalananda

              145k18273452




              145k18273452










              answered Jun 12 '13 at 6:06









              tusharmakkar08tusharmakkar08

              94711221




              94711221













              • Although the date information seems all valid, it does not take the requirement from the internet from the title of the OP into account anywhere.

                – Anthon
                Jun 12 '13 at 7:03











              • I believe that tzdata (time zone data) package synchronizes the data from internet only. Correct me if I am wrong .

                – tusharmakkar08
                Jun 12 '13 at 7:26






              • 3





                tzdata is information about timezones and daylight saving time (start, end, epoch) not the actual date and time. Of course that is handy to know how to get to your local time based on knowledge of your timezone and a UTC time, but you still need to retrieve the latter from the internet.

                – Anthon
                Jun 12 '13 at 7:42













              • You are wrong. time zone data has to be updated (as there are changes happening all the time) BUT it does not update itself automatically from the internet NOR does it set the time from the internet.

                – Ulrich Dangel
                Jun 12 '13 at 8:32











              • @Anthon : I have edited my answer correspondingly.Thank You.

                – tusharmakkar08
                Jun 12 '13 at 9:43



















              • Although the date information seems all valid, it does not take the requirement from the internet from the title of the OP into account anywhere.

                – Anthon
                Jun 12 '13 at 7:03











              • I believe that tzdata (time zone data) package synchronizes the data from internet only. Correct me if I am wrong .

                – tusharmakkar08
                Jun 12 '13 at 7:26






              • 3





                tzdata is information about timezones and daylight saving time (start, end, epoch) not the actual date and time. Of course that is handy to know how to get to your local time based on knowledge of your timezone and a UTC time, but you still need to retrieve the latter from the internet.

                – Anthon
                Jun 12 '13 at 7:42













              • You are wrong. time zone data has to be updated (as there are changes happening all the time) BUT it does not update itself automatically from the internet NOR does it set the time from the internet.

                – Ulrich Dangel
                Jun 12 '13 at 8:32











              • @Anthon : I have edited my answer correspondingly.Thank You.

                – tusharmakkar08
                Jun 12 '13 at 9:43

















              Although the date information seems all valid, it does not take the requirement from the internet from the title of the OP into account anywhere.

              – Anthon
              Jun 12 '13 at 7:03





              Although the date information seems all valid, it does not take the requirement from the internet from the title of the OP into account anywhere.

              – Anthon
              Jun 12 '13 at 7:03













              I believe that tzdata (time zone data) package synchronizes the data from internet only. Correct me if I am wrong .

              – tusharmakkar08
              Jun 12 '13 at 7:26





              I believe that tzdata (time zone data) package synchronizes the data from internet only. Correct me if I am wrong .

              – tusharmakkar08
              Jun 12 '13 at 7:26




              3




              3





              tzdata is information about timezones and daylight saving time (start, end, epoch) not the actual date and time. Of course that is handy to know how to get to your local time based on knowledge of your timezone and a UTC time, but you still need to retrieve the latter from the internet.

              – Anthon
              Jun 12 '13 at 7:42







              tzdata is information about timezones and daylight saving time (start, end, epoch) not the actual date and time. Of course that is handy to know how to get to your local time based on knowledge of your timezone and a UTC time, but you still need to retrieve the latter from the internet.

              – Anthon
              Jun 12 '13 at 7:42















              You are wrong. time zone data has to be updated (as there are changes happening all the time) BUT it does not update itself automatically from the internet NOR does it set the time from the internet.

              – Ulrich Dangel
              Jun 12 '13 at 8:32





              You are wrong. time zone data has to be updated (as there are changes happening all the time) BUT it does not update itself automatically from the internet NOR does it set the time from the internet.

              – Ulrich Dangel
              Jun 12 '13 at 8:32













              @Anthon : I have edited my answer correspondingly.Thank You.

              – tusharmakkar08
              Jun 12 '13 at 9:43





              @Anthon : I have edited my answer correspondingly.Thank You.

              – tusharmakkar08
              Jun 12 '13 at 9:43













              20














              A small code I found to update your time in case you don't want to install anything just to update the date. :)



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





              share|improve this answer



















              • 1





                I use google.in to get the current time for my timezone (INDIA).

                – Dilawar
                Jul 25 '18 at 12:35











              • Note the trailing Z which indicates that the time is given in zulu time zone, so no special timezone manipulation should be needed if the computer timezone is set correctly.

                – user202729
                Sep 6 '18 at 13:13
















              20














              A small code I found to update your time in case you don't want to install anything just to update the date. :)



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





              share|improve this answer



















              • 1





                I use google.in to get the current time for my timezone (INDIA).

                – Dilawar
                Jul 25 '18 at 12:35











              • Note the trailing Z which indicates that the time is given in zulu time zone, so no special timezone manipulation should be needed if the computer timezone is set correctly.

                – user202729
                Sep 6 '18 at 13:13














              20












              20








              20







              A small code I found to update your time in case you don't want to install anything just to update the date. :)



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





              share|improve this answer













              A small code I found to update your time in case you don't want to install anything just to update the date. :)



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






              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Oct 24 '17 at 15:30









              Prashant KabadePrashant Kabade

              30123




              30123








              • 1





                I use google.in to get the current time for my timezone (INDIA).

                – Dilawar
                Jul 25 '18 at 12:35











              • Note the trailing Z which indicates that the time is given in zulu time zone, so no special timezone manipulation should be needed if the computer timezone is set correctly.

                – user202729
                Sep 6 '18 at 13:13














              • 1





                I use google.in to get the current time for my timezone (INDIA).

                – Dilawar
                Jul 25 '18 at 12:35











              • Note the trailing Z which indicates that the time is given in zulu time zone, so no special timezone manipulation should be needed if the computer timezone is set correctly.

                – user202729
                Sep 6 '18 at 13:13








              1




              1





              I use google.in to get the current time for my timezone (INDIA).

              – Dilawar
              Jul 25 '18 at 12:35





              I use google.in to get the current time for my timezone (INDIA).

              – Dilawar
              Jul 25 '18 at 12:35













              Note the trailing Z which indicates that the time is given in zulu time zone, so no special timezone manipulation should be needed if the computer timezone is set correctly.

              – user202729
              Sep 6 '18 at 13:13





              Note the trailing Z which indicates that the time is given in zulu time zone, so no special timezone manipulation should be needed if the computer timezone is set correctly.

              – user202729
              Sep 6 '18 at 13:13











              9














              I use this:



              sudo ntpd -qg; sudo hwclock -w


              first tell ntpd to just set the time and stop after that with -q. Also, in case a your clock has a big error we need to tell ntpd to also adjust in that case with -g. Finally write the clock to hardware to preserve the changes when rebooting with hwclock -w (-w for setting hardwareclock to current system time, there is a difference).






              share|improve this answer



















              • 1





                i tend to do this with a "&&" instead of the semicolon so that if the first command should fail (e.g. network connectivity down) the second command is short-circuited

                – Theophrastus
                Sep 19 '15 at 20:06
















              9














              I use this:



              sudo ntpd -qg; sudo hwclock -w


              first tell ntpd to just set the time and stop after that with -q. Also, in case a your clock has a big error we need to tell ntpd to also adjust in that case with -g. Finally write the clock to hardware to preserve the changes when rebooting with hwclock -w (-w for setting hardwareclock to current system time, there is a difference).






              share|improve this answer



















              • 1





                i tend to do this with a "&&" instead of the semicolon so that if the first command should fail (e.g. network connectivity down) the second command is short-circuited

                – Theophrastus
                Sep 19 '15 at 20:06














              9












              9








              9







              I use this:



              sudo ntpd -qg; sudo hwclock -w


              first tell ntpd to just set the time and stop after that with -q. Also, in case a your clock has a big error we need to tell ntpd to also adjust in that case with -g. Finally write the clock to hardware to preserve the changes when rebooting with hwclock -w (-w for setting hardwareclock to current system time, there is a difference).






              share|improve this answer













              I use this:



              sudo ntpd -qg; sudo hwclock -w


              first tell ntpd to just set the time and stop after that with -q. Also, in case a your clock has a big error we need to tell ntpd to also adjust in that case with -g. Finally write the clock to hardware to preserve the changes when rebooting with hwclock -w (-w for setting hardwareclock to current system time, there is a difference).







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Jun 12 '13 at 8:58









              SilverrockerSilverrocker

              1,197920




              1,197920








              • 1





                i tend to do this with a "&&" instead of the semicolon so that if the first command should fail (e.g. network connectivity down) the second command is short-circuited

                – Theophrastus
                Sep 19 '15 at 20:06














              • 1





                i tend to do this with a "&&" instead of the semicolon so that if the first command should fail (e.g. network connectivity down) the second command is short-circuited

                – Theophrastus
                Sep 19 '15 at 20:06








              1




              1





              i tend to do this with a "&&" instead of the semicolon so that if the first command should fail (e.g. network connectivity down) the second command is short-circuited

              – Theophrastus
              Sep 19 '15 at 20:06





              i tend to do this with a "&&" instead of the semicolon so that if the first command should fail (e.g. network connectivity down) the second command is short-circuited

              – Theophrastus
              Sep 19 '15 at 20:06











              7














              Use ntpdate, ntpd, or Chrony to connect to a NTP server.






              share|improve this answer




























                7














                Use ntpdate, ntpd, or Chrony to connect to a NTP server.






                share|improve this answer


























                  7












                  7








                  7







                  Use ntpdate, ntpd, or Chrony to connect to a NTP server.






                  share|improve this answer













                  Use ntpdate, ntpd, or Chrony to connect to a NTP server.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jun 12 '13 at 5:42









                  Ignacio Vazquez-AbramsIgnacio Vazquez-Abrams

                  34k66984




                  34k66984























                      5














                      Some distributions are shipping rdate for that purpose. Basic usage:



                      # just query
                      bash-4.2$ rdate pool.ntp.org
                      rdate: [pool.ntp.org] Wed Jun 12 11:05:40 2013

                      # set system time
                      bash-4.2$ rdate -s pool.ntp.org





                      share|improve this answer
























                      • Way better and easier than ntp

                        – andrewtweber
                        Mar 30 '16 at 18:39











                      • pool.ntp.org now refuses connections from rdate. time.nist.gov works. Also once you have set the system time, you should set the hardware clock as well by running hwclock -w to set it to the system time. You can then verify it is correct by running hwclock -r

                        – MatthewLee
                        Jul 14 '17 at 14:53
















                      5














                      Some distributions are shipping rdate for that purpose. Basic usage:



                      # just query
                      bash-4.2$ rdate pool.ntp.org
                      rdate: [pool.ntp.org] Wed Jun 12 11:05:40 2013

                      # set system time
                      bash-4.2$ rdate -s pool.ntp.org





                      share|improve this answer
























                      • Way better and easier than ntp

                        – andrewtweber
                        Mar 30 '16 at 18:39











                      • pool.ntp.org now refuses connections from rdate. time.nist.gov works. Also once you have set the system time, you should set the hardware clock as well by running hwclock -w to set it to the system time. You can then verify it is correct by running hwclock -r

                        – MatthewLee
                        Jul 14 '17 at 14:53














                      5












                      5








                      5







                      Some distributions are shipping rdate for that purpose. Basic usage:



                      # just query
                      bash-4.2$ rdate pool.ntp.org
                      rdate: [pool.ntp.org] Wed Jun 12 11:05:40 2013

                      # set system time
                      bash-4.2$ rdate -s pool.ntp.org





                      share|improve this answer













                      Some distributions are shipping rdate for that purpose. Basic usage:



                      # just query
                      bash-4.2$ rdate pool.ntp.org
                      rdate: [pool.ntp.org] Wed Jun 12 11:05:40 2013

                      # set system time
                      bash-4.2$ rdate -s pool.ntp.org






                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Jun 12 '13 at 8:07









                      manatworkmanatwork

                      22.4k38386




                      22.4k38386













                      • Way better and easier than ntp

                        – andrewtweber
                        Mar 30 '16 at 18:39











                      • pool.ntp.org now refuses connections from rdate. time.nist.gov works. Also once you have set the system time, you should set the hardware clock as well by running hwclock -w to set it to the system time. You can then verify it is correct by running hwclock -r

                        – MatthewLee
                        Jul 14 '17 at 14:53



















                      • Way better and easier than ntp

                        – andrewtweber
                        Mar 30 '16 at 18:39











                      • pool.ntp.org now refuses connections from rdate. time.nist.gov works. Also once you have set the system time, you should set the hardware clock as well by running hwclock -w to set it to the system time. You can then verify it is correct by running hwclock -r

                        – MatthewLee
                        Jul 14 '17 at 14:53

















                      Way better and easier than ntp

                      – andrewtweber
                      Mar 30 '16 at 18:39





                      Way better and easier than ntp

                      – andrewtweber
                      Mar 30 '16 at 18:39













                      pool.ntp.org now refuses connections from rdate. time.nist.gov works. Also once you have set the system time, you should set the hardware clock as well by running hwclock -w to set it to the system time. You can then verify it is correct by running hwclock -r

                      – MatthewLee
                      Jul 14 '17 at 14:53





                      pool.ntp.org now refuses connections from rdate. time.nist.gov works. Also once you have set the system time, you should set the hardware clock as well by running hwclock -w to set it to the system time. You can then verify it is correct by running hwclock -r

                      – MatthewLee
                      Jul 14 '17 at 14:53











                      4














                      After some research, I ended up with this. I also applied it to my own server:



                      sudo apt-get install ntp
                      sudo dpkg-reconfigure ntp
                      ntpq -p


                      If the last command shows a valid list of servers, you are good to go. The command will run a quite complex set of algorithms which will iterate your clock drift, among other things, and compensate for them. You will end up with a pretty accurate clock even if you lose the connection to the NTP servers. However, the command does require a few minutes to get started.



                      Source: here and here.






                      share|improve this answer




























                        4














                        After some research, I ended up with this. I also applied it to my own server:



                        sudo apt-get install ntp
                        sudo dpkg-reconfigure ntp
                        ntpq -p


                        If the last command shows a valid list of servers, you are good to go. The command will run a quite complex set of algorithms which will iterate your clock drift, among other things, and compensate for them. You will end up with a pretty accurate clock even if you lose the connection to the NTP servers. However, the command does require a few minutes to get started.



                        Source: here and here.






                        share|improve this answer


























                          4












                          4








                          4







                          After some research, I ended up with this. I also applied it to my own server:



                          sudo apt-get install ntp
                          sudo dpkg-reconfigure ntp
                          ntpq -p


                          If the last command shows a valid list of servers, you are good to go. The command will run a quite complex set of algorithms which will iterate your clock drift, among other things, and compensate for them. You will end up with a pretty accurate clock even if you lose the connection to the NTP servers. However, the command does require a few minutes to get started.



                          Source: here and here.






                          share|improve this answer













                          After some research, I ended up with this. I also applied it to my own server:



                          sudo apt-get install ntp
                          sudo dpkg-reconfigure ntp
                          ntpq -p


                          If the last command shows a valid list of servers, you are good to go. The command will run a quite complex set of algorithms which will iterate your clock drift, among other things, and compensate for them. You will end up with a pretty accurate clock even if you lose the connection to the NTP servers. However, the command does require a few minutes to get started.



                          Source: here and here.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Mar 30 '15 at 20:00









                          TubblesTubbles

                          412




                          412























                              0














                              To find "peers" (hosts you can query) you can use ntpq -p.



                              If you already have an NTP service running you have to stop it before manually updating, for example using sudo service ntp stop.



                              Now you can query a peer, for example using sudo ntpdate "peer".






                              share|improve this answer




























                                0














                                To find "peers" (hosts you can query) you can use ntpq -p.



                                If you already have an NTP service running you have to stop it before manually updating, for example using sudo service ntp stop.



                                Now you can query a peer, for example using sudo ntpdate "peer".






                                share|improve this answer


























                                  0












                                  0








                                  0







                                  To find "peers" (hosts you can query) you can use ntpq -p.



                                  If you already have an NTP service running you have to stop it before manually updating, for example using sudo service ntp stop.



                                  Now you can query a peer, for example using sudo ntpdate "peer".






                                  share|improve this answer













                                  To find "peers" (hosts you can query) you can use ntpq -p.



                                  If you already have an NTP service running you have to stop it before manually updating, for example using sudo service ntp stop.



                                  Now you can query a peer, for example using sudo ntpdate "peer".







                                  share|improve this answer












                                  share|improve this answer



                                  share|improve this answer










                                  answered Jun 12 '13 at 7:55









                                  l0b0l0b0

                                  29k20122252




                                  29k20122252























                                      0














                                      Using rdate tool as suggested in manatwork's answer, but with SNTP protocol -n and IPv4 -4 options on:



                                      # just print synced time, not set
                                      rdate -n -4 -p time-a.nist.gov

                                      # print and set synced time
                                      sudo rdate -n -4 time-a.nist.gov


                                      The tool may be installed on Debian this way:



                                      sudo apt-get install rdate





                                      share|improve this answer




























                                        0














                                        Using rdate tool as suggested in manatwork's answer, but with SNTP protocol -n and IPv4 -4 options on:



                                        # just print synced time, not set
                                        rdate -n -4 -p time-a.nist.gov

                                        # print and set synced time
                                        sudo rdate -n -4 time-a.nist.gov


                                        The tool may be installed on Debian this way:



                                        sudo apt-get install rdate





                                        share|improve this answer


























                                          0












                                          0








                                          0







                                          Using rdate tool as suggested in manatwork's answer, but with SNTP protocol -n and IPv4 -4 options on:



                                          # just print synced time, not set
                                          rdate -n -4 -p time-a.nist.gov

                                          # print and set synced time
                                          sudo rdate -n -4 time-a.nist.gov


                                          The tool may be installed on Debian this way:



                                          sudo apt-get install rdate





                                          share|improve this answer













                                          Using rdate tool as suggested in manatwork's answer, but with SNTP protocol -n and IPv4 -4 options on:



                                          # just print synced time, not set
                                          rdate -n -4 -p time-a.nist.gov

                                          # print and set synced time
                                          sudo rdate -n -4 time-a.nist.gov


                                          The tool may be installed on Debian this way:



                                          sudo apt-get install rdate






                                          share|improve this answer












                                          share|improve this answer



                                          share|improve this answer










                                          answered Sep 19 '15 at 19:19









                                          SergeanTSergeanT

                                          1012




                                          1012























                                              0














                                              In addition to Tushar's reply, I also had to do apt-get install ntpdate on my Ubuntu 14.04.



                                              Posting as answer because reputation does not suffice for commenting.






                                              share|improve this answer






























                                                0














                                                In addition to Tushar's reply, I also had to do apt-get install ntpdate on my Ubuntu 14.04.



                                                Posting as answer because reputation does not suffice for commenting.






                                                share|improve this answer




























                                                  0












                                                  0








                                                  0







                                                  In addition to Tushar's reply, I also had to do apt-get install ntpdate on my Ubuntu 14.04.



                                                  Posting as answer because reputation does not suffice for commenting.






                                                  share|improve this answer















                                                  In addition to Tushar's reply, I also had to do apt-get install ntpdate on my Ubuntu 14.04.



                                                  Posting as answer because reputation does not suffice for commenting.







                                                  share|improve this answer














                                                  share|improve this answer



                                                  share|improve this answer








                                                  edited Apr 13 '17 at 12:36









                                                  Community

                                                  1




                                                  1










                                                  answered Feb 7 '17 at 16:21









                                                  pylipppylipp

                                                  32




                                                  32























                                                      0














                                                      I also was looking for a non ntp/ntpd way of resetting clock periodically. I liked the google.com header parsing but found it did not work on ubuntu. I think this will also work on a Raspberry Pi.



                                                      sudo date +"%d %b %Y %T %Z" -s "$(wget -qSO- --max-redirect=0 http://google.com 2>&1 | grep '^  Date:' | cut -d' ' -f 5-)"





                                                      share|improve this answer








                                                      New contributor




                                                      Ron B is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                      Check out our Code of Conduct.

























                                                        0














                                                        I also was looking for a non ntp/ntpd way of resetting clock periodically. I liked the google.com header parsing but found it did not work on ubuntu. I think this will also work on a Raspberry Pi.



                                                        sudo date +"%d %b %Y %T %Z" -s "$(wget -qSO- --max-redirect=0 http://google.com 2>&1 | grep '^  Date:' | cut -d' ' -f 5-)"





                                                        share|improve this answer








                                                        New contributor




                                                        Ron B is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                        Check out our Code of Conduct.























                                                          0












                                                          0








                                                          0







                                                          I also was looking for a non ntp/ntpd way of resetting clock periodically. I liked the google.com header parsing but found it did not work on ubuntu. I think this will also work on a Raspberry Pi.



                                                          sudo date +"%d %b %Y %T %Z" -s "$(wget -qSO- --max-redirect=0 http://google.com 2>&1 | grep '^  Date:' | cut -d' ' -f 5-)"





                                                          share|improve this answer








                                                          New contributor




                                                          Ron B is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                          Check out our Code of Conduct.










                                                          I also was looking for a non ntp/ntpd way of resetting clock periodically. I liked the google.com header parsing but found it did not work on ubuntu. I think this will also work on a Raspberry Pi.



                                                          sudo date +"%d %b %Y %T %Z" -s "$(wget -qSO- --max-redirect=0 http://google.com 2>&1 | grep '^  Date:' | cut -d' ' -f 5-)"






                                                          share|improve this answer








                                                          New contributor




                                                          Ron B is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                          Check out our Code of Conduct.









                                                          share|improve this answer



                                                          share|improve this answer






                                                          New contributor




                                                          Ron B is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                          Check out our Code of Conduct.









                                                          answered 15 mins ago









                                                          Ron BRon B

                                                          1




                                                          1




                                                          New contributor




                                                          Ron B is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                          Check out our Code of Conduct.





                                                          New contributor





                                                          Ron B is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                          Check out our Code of Conduct.






                                                          Ron B is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                          Check out our Code of Conduct.






























                                                              draft saved

                                                              draft discarded




















































                                                              Thanks for contributing an answer to Unix & Linux Stack Exchange!


                                                              • Please be sure to answer the question. Provide details and share your research!

                                                              But avoid



                                                              • Asking for help, clarification, or responding to other answers.

                                                              • Making statements based on opinion; back them up with references or personal experience.


                                                              To learn more, see our tips on writing great answers.




                                                              draft saved


                                                              draft discarded














                                                              StackExchange.ready(
                                                              function () {
                                                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f79112%2fhow-do-i-set-time-and-date-from-the-internet%23new-answer', 'question_page');
                                                              }
                                                              );

                                                              Post as a guest















                                                              Required, but never shown





















































                                                              Required, but never shown














                                                              Required, but never shown












                                                              Required, but never shown







                                                              Required, but never shown

































                                                              Required, but never shown














                                                              Required, but never shown












                                                              Required, but never shown







                                                              Required, but never shown







                                                              Popular posts from this blog

                                                              Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

                                                              Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

                                                              Nicolae Petrescu-Găină Cuprins Biografie | Opera | In memoriam | Varia | Controverse, incertitudini...