The first thing I would suggest to do before buying and installing a new battery is to reset your PRAM. To do this, restart the computer and before the grey screen comes up you have to be holding down Command-Option-P-R simultaneously. Continue holding these down until you hear the startup chime 3 times total, then let go. For better instructions on how to do this and information on what's actually stored in the parameter RAM, go to
http://kbase.info.apple.com and search for article number 2238.
If this doesn't remedy the clock resetting, then try resetting your Power Management Unit (PMU). To do this, you actually have to physically push a button located near the internal battery on the logic board. Follow the instructions on Apples Knowledge Base in article number 95037. They have links to diagrams of the logic board of most G4's, so you should have no problem locating this button. Read the instructions in this article carefully. Doing this wrong could damage your computer and could cause the battery life to go from 5 years to about 2 days if the PMU isn't reset properly.
As a last resort if these two things don't correct the time resetting intermittently, reset Open Firmware. To do this, restart the computer and hold down Command-Option-O-F during the startup chime. A white screen should come up with a bunch of jibberish about the version of Open Firmware you have installed. From here, (all lowercase, no spaces, no quotes) type "reset-all" and hit return. It will restart your computer and reset Open Firmware settings to their default.
None of these steps will damage any data on your hard drive or cause any damage to the computer itself. The most it will do is reset your date and time and reset other settings outlined in the article I mentioned about resetting PRAM.
It could be a file corrupted on your hard drive, so you could also try running fsck from single user mode in OS X. Restart the computer holding down Command-S, and when it finishes loading and gets to the point where you can type in a command, type "fsck -y" (no quotes, all lowercase) and if it finds any errors and has to modify your file system, run it again until it doesn't find any errors. When it reports "Volume appears to be ok", then type "reboot" and hit return to startup OS X normally.
If none of these things work, then yeah, you should go buy a new battery : ]
Good luck.