Equivalence of partition functions for U(1) gauge theory and its dual in appropriate phase spaces is established in terms of constrained hamiltonian formalism of their parent action. Relations between the electric--magnetic duality transformation and the (S) duality transformation which inverts the strong coupling domains to the weak coupling domains of noncommutative U(1) gauge theory are discussed in terms of the lagrangian and the hamiltonian densities. The approach presented for the commutative case is utilized to demonstrate that noncommutative U(1) gauge theory and its dual possess the same partition function in their phase spaces at the first order in the noncommutativity parameter theta .