The skyrocketing growth in types and number of heterogeneous applications dramatically increases the amount of energy consumed by distributed green data centers (DGDCs). The spatial and temporal variations in prices of power grid and availability of renewable energy make it highly challenging to minimize the energy cost by intelligently scheduling arriving tasks of heterogeneous applications among green data centers while meeting their expected delay bound constraints. Unlike existing studies, this work proposes a Spatio-Temporal Task Scheduling (STTS) algorithm to minimize the energy cost by cost-effectively scheduling all arriving tasks to meet their delay bound constraints. It well uses spatial and temporal variations to achieve DGDC cost reduction and throughput improvement. In each time slot, the energy cost minimization problem for DGDC providers is formulated as a nonlinear constrained optimization one, and addressed with the proposed Genetic Simulated-annealing-based Particle swarm optimization. Trace-driven experiments show that STTS achieves larger throughput and lower energy cost than several typical task scheduling approaches while strictly meeting all tasks' delay bound constraints.