Clock programming

have a look at the examples in the RTC library folder. The virtually do it all for you.