Spectrally accurate space-time solution of Hamiltonian PDEs