What I want to do, is to combine these two methods
Then all you have to do is install an RTC.
The NTP daemon which is used to set the time on the pi is also commonly used on systems with a clock to keep it synchronized with the real world and occasionally correct the small amount of "drift" standard computer clocks are often prone to.
The daemon can be annoying initially if it cannot make an internet connection to verify and correct the time since it reports this to the kernel as a serious problem (i.e., one which gets spit to the console), but this does not persist and does not cause any issues beyond that unless something is bound to its success, which by default on Raspbian nothing is as far as I am aware (I think it is only a genuinely serious problem when clustering or in other contexts where physically separate systems are intimately bound and synchronizing data at a high rate -- in which case they should sync clocks as soon as they link).
Although it is perhaps poorly designed in other ways from a user perspective, it at least has copious documention (you can get the current version with ntpd --version
), parts of which you may wish to read through. Don't get your hopes up about making it less annoying, but it can be tweaked with regard to various parameters such as how quickly it updates the clock when a discrepancy is found.
Beware the difference between the system time, and the hardware time; the system time is actually what is most significant for general operation, but if the hardware time is not also updated, the system time will need correcting again at next boot, which can cause certain things to complain if it is behind and you do a quick reboot (these things will notice timestamps that appear to be in the future).
It sounds like Raspbian (or ntpd
itself) will keep the system time and the hardware clock synchronized (see comments below). If this turns out not to be the case for you it is easy to solve (see man hwclock
).