Cosymplectic and contact structures for time-dependent and dissipative Hamiltonian systems