Ocean water exhibits periodic motion both temporally and spatially. However, no time-varying mechanism has been studied for harvesting energy from dynamic ocean. This paper presents an enhanced mechanism for harvesting the energy of ocean flows by applying time-varying stiffness adaptation in dynamic ocean environments, resulting in superior performance. By conducting numerical simulations and experiments, this study investigates the motion response and energy harvesting characteristics of a single oscillating cylinder equipped with time-varying stiffness. The research focuses on examining its behavior in both uniform flow and shear flow conditions, and presents several noteworthy findings. First, in comparison to impulse and trapezoid patterns, the sin-patterned time-varying stiffness demonstrates superior energy harvesting performance in both uniform flow and time-varying flow conditions. Second, the frequency of the sin-patterned time-varying stiffness is a critical parameter that influences the energy harvesting performance. Setting the sin-patterned time-varying stiffness frequency to ωv = 0.75ωn (natural frequency of constant stiffness) yields optimal performance under both uniform and time-varying flow conditions. At ωv = 0.75ωn, the energy-harvesting power can be increased by more than 30 times compared to the case of constant stiffness. Simultaneously, the oscillator's motion frequency experiences a reduction of over 40%. It is within this frequency range that the energy-harvesting power is maximized across the entire frequency spectrum. Third, as the frequency of sin-patterned time-varying stiffness increases, there is a decrease in both the energy harvesting power and efficiency. At a frequency of ωv/ωn* = 1.5, the advantage over the constant stiffness oscillator becomes negligible. Fourth, the energy harvesting performance of time-varying stiffness is superior in a time-varying flow condition compared to a uniform flow condition. The maximum energy harvesting power is achieved at ωv/ωn* = 0.75 in the time-varying flow condition, surpassing the corresponding value in the uniform flow condition. Fifth, the phase-shift resonance between the shedding frequency and the frequency of time-varying stiffness significantly enhances the energy harvesting performance of the time-varying stiffness oscillator. The optimal time-varying frequency is determined to have a phase difference of 0.15ωn. Sixth, the power harvesting efficiency can be improved by up to 1.5 times on average using the time-varying stiffness mechanism (sin-patterned, 10% additional power required) compared to state-of-the-art technologies employing constant stiffness. Finally, matching the form and dominant frequency of the excitation force with those of the time-varying stiffness can greatly improve the energy harvesting power and motion amplitude of the oscillator. This paper explores a performance-based approach to energy harvesting in dynamic ocean environments by applying sin-patterned time-varying stiffness with ωv = 0.75ωn.