Populations living in a spatially and temporally changing environment can adapt to the changing optimum and/or migrate toward favorable habitats. Here we extend previous analyses with a static optimum to allow the environment to vary in time as well as in space. The model follows both population dynamics and the trait mean under stabilizing selection, and the outcomes can be understood by comparing the loads due to genetic variance, dispersal, and temporal change. With fixed genetic variance, we obtain two regimes: (1) adaptation that is uniform along the environmental gradient and that responds to the moving optimum as expected for panmictic populations and when the spatial gradient is sufficiently steep, and (2) a population with limited range that adapts more slowly than the environmental optimum changes in both time and space; the population therefore becomes locally extinct and migrates toward suitable habitat. We also use a population-genetic model with many loci to allow genetic variance to evolve, and we show that the only solution now has uniform adaptation.