In this paper we give necessary and sufficient conditions for achieving a quadratic positive definite time-invariant Hamiltonian for time-varying generalized Hamiltonian control systems using canonical transformations. Those necessary and sufficient conditions form a system of partial differential equations that reduces to the matching conditions obtained earlier in the literature for time-invariant systems. Their theoretical solvability is proved via the Cauchy-Kowalevskaya theorem and their practical solvability discussed in some particular cases. Systems with time-invariant positive definite Hamiltonian are known to yield a passive input-output map and can be stabilized by unity feedback, which underlines the importance of achieving the positive definiteness and time-invariancy for the Hamiltonian. We illustrate the results with few examples including the rolling coin.