Derivation of a generalized Langevin equation from a generic time-dependent Hamiltonian