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.
Follow these steps to set the time servers and the time zone:
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
Open
/etc/ntp.conf
in a text editor. If you use thenano
editor, runsudo nano /etc/ntp.conf
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
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
Comment out (by adding a
#
in front of the line) the following two lines:restrict 127.0.0.1 restrict ::1
Save the file and exit
Set the correct time zone by running
sudo cp /usr/share/zoneinfo/US/Pacific /etc/localtime
. ReplaceUS/Pacific
with your time zone. If you are not sure about the possible values, look in/usr/share/zoneinfo
Restart the
ntp
server:sudo /etc/init.d/ntp restart
Run
date
in a terminalIf 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. Runsudo ntpd -gq
and then restartntp