We study the time-dependent modulation effect and derive the local interstellar spectra (LIS) for the cosmic ray (CR) proton, helium, boron and carbon. A two-dimensional modulation model including the variation of the interplanetary environment with time is adopted to describe modulation process. The propagation equation of CRs in the heliosphere is numerically solved by the package Solarprop. We derive the LIS by fitting the latest results of several experiments, including Voyager 1, PAMELA, BESS-POLARII and ACE, during low solar activity periods. We further study the modulation in the polarity reversal periods with the PAMELA proton data. We find that the rigidity dependence of the diffusion coefficient is critical to explain the modulation effect during reversal periods. Our results also indicate a power law relation between the diffusion coefficient and the magnitude of the heliospheric magnetic field (HMF) at the Earth.