The direction of the magnetic field created by an electric current is determined by the direction of the electric current as demonstrated by the "right hand rule".
A D.C. current is one in which the current travels in the same direction through the entire time the current is running. Therefore, the magnetic field created will be in the same direction the entire time.
An A.C. current is a current that alternates its direction in opposite directions as the current is applied. Each time the current alters its direction the magnetic field will also change its direction. Consequently, the polarity of the electromagnet will switch directions each as the current is applied.