  We study the dynamics of magnetic flows on Heisenberg groups. Let $H$ denote
the three-dimensional simply connected Heisenberg Lie group endowed with a
left-invariant Riemannian metric and an exact, left-invariant magnetic field.
Let $\Gamma$ be a lattice subgroup of $H,$ so that $\Gamma\backslash H$ is a
closed nilmanifold. We first find an explicit description of magnetic geodesics
on $H$, then determine all closed magnetic geodesics and their lengths for
$\Gamma \backslash H$. We then consider two applications of these results: the
density of periodic magnetic geodesics and marked magnetic length spectrum
rigidity.
