The motion of a mass on a spring, with spring constant K is as shown in figure.

The equation of motion is given by
x(t) = A sin$\omega$t + B cos$\omega$t with $\omega$ = $\sqrt {{K \over m}} $
Suppose that at time t = 0, the position of mass is x(0) and velocity v(0), then its displacement can also be represented as x(t) = C cos($\omega$t $-$ $\phi$), where C and $\phi$ are :
$C = \sqrt {{{2v{{(0)}^2}} \over {{\omega ^2}}} + x{{(0)}^2}} ,\phi = {\tan ^{ - 1}}\left( {{{x(0)\omega } \over {2v(0)}}} \right)$
$C = \sqrt {{{v{{(0)}^2}} \over {{\omega ^2}}} + x{{(0)}^2}} ,\phi = {\tan ^{ - 1}}\left( {{{x(0)\omega } \over {v(0)}}} \right)$
$C = \sqrt {{{v{{(0)}^2}} \over {{\omega ^2}}} + x{{(0)}^2}} ,\phi = {\tan ^{ - 1}}\left( {{{v(0)} \over {x(0)\omega }}} \right)$
$C = \sqrt {{{2v{{(0)}^2}} \over {{\omega ^2}}} + x{{(0)}^2}} ,\phi = {\tan ^{ - 1}}\left( {{{v(0)} \over {x(0)\omega }}} \right)$