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.orgOpen
/etc/ntp.confin a text editor. If you use thenanoeditor, runsudo nano /etc/ntp.confYou 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 iburstReplace 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 iburstComment out (by adding a
#in front of the line) the following two lines:restrict 127.0.0.1 restrict ::1Save the file and exit
Set the correct time zone by running
sudo cp /usr/share/zoneinfo/US/Pacific /etc/localtime. ReplaceUS/Pacificwith your time zone. If you are not sure about the possible values, look in/usr/share/zoneinfoRestart the
ntpserver:sudo /etc/init.d/ntp restartRun
datein a terminalIf the time is not correct, you might have to force update it. This is because, by default,
ntpwill not sync if the difference between the system time and the real-time is greater that 1000 seconds. Runsudo ntpd -gqand then restartntp