While solar power systems have offered a wide variety of electricity generation approaches including photovoltaics, solar thermal power systems, and solar thermoelectric generators, the ability of generating electricity at both the daytime and nighttime with no necessity of energy storage still remains challenging. Here, we propose and verify a strategy of harvesting solar energy by solar heating during the daytime and harnessing the coldness of the outer space through radiative cooling to produce electricity at night using a commercial thermoelectric module. It enables electricity generation for 24 hours a day. We experimentally demonstrate a peak power density of 37 mW/m2 at night and a peak value of 723 mW/m2 during the daytime. A theoretical model that accurately predicts the performance of the device is developed and validated. The feature of 24-hour electricity generation shows great potential energy applications of off-grid and battery-free lighting and sensing.