If your signature is accurate you have an iMac5,1 and according to MacTracker, the iMac5,1 (17" 2 GHz Intel Core 2 Duo processor) has a 3 V CR2032 lithium (922-6476) Backup (a.k.a. PRAM) battery that among other things would be responsible for keeping the clock running when power is disconnected. If you have never replaced it is almost dead certain the battery has failed — a long time ago.
I found the
Service Manual for the IMac5,1 and changing the battery is not a job for amateurs, or the faint of heart. It requires removing the memory access door, the front bezel, and the lower EMI shield just to get to the battery. After that removing and replacing the battery is pretty much a cinch except that you then need to replace everything you previously removed. (see page 43 of the referenced Service Manual. To get to the Optical drive requires removing a lot more stuff. I don't know what your skill level is, but I would be looking for an Apple Certified Repair Center (The iMac5,1 is obsolete so the "Genius Desk" at the Apple Store is not supposed to work on it. 😞