Raspberry Pi How To: Install Real Time Clock

There are plenty of articles on the installation of a DS1307 RTC module.

There are equally as many articles listing various installation/configuration problems.

The basic hardware issues relates to signal voltage difference on I2C bus, the Pi uses 3.3V whereas the DS1307 module uses 5V. You may decide to remove the pulp resistors from the DS1307.
Same DS1307 modules cater for both, a CR2032 battery and a rechargeable battery. You may have to remove the charge resistor if you are using a non-rechargeable battery. 

The article describes the configuration steps for systemd based Raspbian (not Wheezy or anything earlier)
Thanks to KD8TWG and Adafruit for some of the information shown on this page.

Step 1 - edit /boot/config.txt and add

dtoverlay=i2c-rtc,ds1307

You should also ensure that the I2C bus is enabled (dtparam=i2c_arm=on) in config.txt.

Step 2 - execute "i2cdetect -y 1"

You should see "UU" at address 0x68. you may also see "50" if the RTC module contains an EEPROM chip.

Step 3 - disable fake hwclock

apt-get -y remove fake-hwclock
update-rc.d -f fake-hwclock remove
systemctl disable fake-hwclock

Step 4 - change /lib/udev/hwclock-set by commenting out the following lines:

#if [ -e /run/systemd/system ] ; then
#    exit 0
#fi

also comment out these lines: 

#/sbin/hwclock --rtc=$dev --systz --badyear
#/sbin/hwclock --rtc=$dev --systz 

Step 5 - timesyncd service which must be disabled or the system clock will not be synced to RTC module on boot.

systemctl stop systemd-timesyncd.service
systemctl disable systemd-timesyncd.service

To set the correct time:

Sync system time (e.g. via ntp)
then use "hwclock -w" to write system time to RTC module

The RTC clock can be read at any time with "hwclock -r" and the system time can be synced to the RTC time with "hwclock -s".

For more information on the hwclock command: "man hwclock"