Raspberry Pi sync date and time



The Raspberry Pi does not have a RTC (Real Time Clock) module and it is not able to keep the date and time without a power source. If your Raspberry Pi is not connected to the Internet, you are out of luck and the only option is to buy and install an RTC module. However, if it has Internet, you can make it sync the date and time from a time-server.

datetime

Follow these steps to set the time servers and the time zone:

  1. Go to http://support.ntp.org/bin/view/Servers/NTPPoolServers and click the host name corresponding to your area. Assuming the area is North America, the servers are:

      server 0.north-america.pool.ntp.org
      server 1.north-america.pool.ntp.org
      server 2.north-america.pool.ntp.org
      server 3.north-america.pool.ntp.org
    
  2. Open /etc/ntp.conf in a text editor. If you use the nano editor, run sudo nano /etc/ntp.conf

  3. You should see a list of servers similar to the one below:

      server 0.dk.pool.ntp.org iburst
      server 1.dk.pool.ntp.org iburst
      server 2.dk.pool.ntp.org iburst
      server 3.dk.pool.ntp.org iburst
    
  4. Replace the servers with the ones from step 1:

      server 0.north-america.pool.ntp.org iburst
      server 1.north-america.pool.ntp.org iburst
      server 2.north-america.pool.ntp.org iburst
      server 3.north-america.pool.ntp.org iburst
    
  5. Comment out (by adding a # in front of the line) the following two lines:

      restrict 127.0.0.1
      restrict ::1
    
  6. Save the file and exit

  7. Set the correct time zone by running sudo cp /usr/share/zoneinfo/US/Pacific /etc/localtime. Replace US/Pacific with your time zone. If you are not sure about the possible values, look in /usr/share/zoneinfo

  8. Restart the ntp server: sudo /etc/init.d/ntp restart

  9. Run date in a terminal

  10. If the time is not correct, you might have to force update it. This is because, by default, ntp will not sync if the difference between the system time and the real-time is greater that 1000 seconds. Run sudo ntpd -gq and then restart ntp