A calcium myristic superhydrophobicity coating with a hierarchical micro-nanostructure was fabricated on AZ31 magnesium alloy by one-step electroposition. The effects of deposition time on the coating structure, such as morphology, thickness, wettability and phase composition of the coating were studied. The corrosion behavior of the coated samples in 3.5% NaCl solution was also investigated and the corrosion mechanism was discussed. It was found that the deposition time has a visible effect on the morphology, thickness and wettability, which distinctly affects the corrosion resistance of coatings. The corrosion resistance of the coating gradually decreases with the increase in the immersion time due to the disappearance of the air layer which exists on the coating surface. The superhydrophobic surfaces present the temporal limitations to the corrosion resistance of AZ31 magnesium alloy.