Difficulty keeping car engine operating

I do not drive the car very often. Recently, when I start the car (it starts perfectly and almost immediately) and let it idle to charge the battery, the engine stops after about 30 - 35 minutes. When I try to start it, the engine turns over and over, but will not start. If I wait about 3 hours and try again, the engine runs roughly for about 10 seconds but will not start. If I wait about 8 hours, the engine starts perfectly!