The virial theorem is derived in quantum statistical mechanics for a time-dependent Hamiltonian that describes a charged particle in a time-dependent electromagnetic field. The time derivative of the expectation value of the Clausius operator satisfies an equation which is the same form as the classical equation for the Clausius function (r⋅mv). By taking a time average, the virial theorem of quantum mechanics for time-dependent states is obtained. By taking a statistical average and a time average, the virial theorem of quantum statistical mechanics is obtained.