Why does the acceleration $g$ due to gravity not affect the period of a vertically mounted spring? For a vertically mounted spring, I was looking at the formula $ T= 2\pi \sqrt{m/k}$ for a period. Why doesn't the gravitational acceleration $g$ factor in? 
 A: Just look at the equation of motion.
Suppose you hang a spring from the ceiling, and that it hangs a distance $y_0$ from the ceiling in equilibrium (we orient our axis so that positive $y$ points downward).  Then, the equation of motion is
$$
m\ddot{y}=-k(y-y_0)+mg,
$$
and so
$$
\tfrac{\mathrm{d}^2}{\mathrm{d}t^2}(y-y_0)+\tfrac{k}{m}(y-y_0)=g.
$$
The square of the frequency is given by the coefficient of $y-y_0$, in this case $\frac{k}{m}$, which you'll note does not involve $g$.
A: The period of oscillation depends on the restoring force and the inertia (mass) which is oscillating. 
Gravity is a constant force. When the mass is in its equilibrium position this force is balanced by the spring force. When the mass moves away from equilibrium the force of gravity does not change, only the spring force changes. The restoring force is caused only by the spring force.  
Although gravity affects what the equilibrium extension will be, it is not the restoring force, so it does not affect the period of oscillation of a mass on a spring.
However, gravity does affect the period of a pendulum. The gravitational force on the pendulum mass is constant and independent of displacement, but the moment of this force - which causes the pendulum string to rotate back towards the equilibrium position - is not constant. It increases with the angular displacement. The restoring moment (torque) depends on gravity, so gravity affects the period of a pendulum.
A: The effect of gravity is only to shift the equilibrium point, so at equilibrium (at rest), a vertical spring will be extended as compared with the same spring in a horizontal position. But this does not affect the period. 
The equation for the dynamics of the spring is $m\frac{d^2x}{dt^2}=-kx+mg$. You can change the variable $x$ to $x'=x+mg/k$ and get $m\frac{d^2x'}{dt^2}=-kx'$. So the dynamics is equivalent to that of spring with the same constant but with the equilibrium point shifted by a distance $mg/k$
Update:
when you replace $x$ in you equation you have $x=x'-mg/k$ so you get $m\frac{d^2(x'-mg/k)}{dt^2}=-k(x'-mg/k)+mg$
On the left side you have $m\frac{d^2(x'-mg/k)}{dt^2}=m\frac{d^2x'}{dt^2}$ because the derivative of a constant ($mg/k$) is zero, and on the right side you get $-kx'$ after distributing. 
A: When we hang  spring pendulum then the net force on that pendulum is zero that is one force is gravity and another forces Is against Gravity So we can set that the pendulum is in equilibrium because the net force is zero now if we applied an external force to pendulum then it's shift By some displacement and SHM will start.
A: I didn't see this answer so I would include it for completeness.
So the three base parameters at work here are mass with unit $\text{kg}$, gravitational acceleration with unit $\text{m}/\text{s}^2$, and a spring constant with unit $\text{kg}/\text{s}^2$.
Dimensional analysis states that you can only feed to an arbitrary mathematical function an expression which has no units; you find all ways to combine your base parameters into unitless parameters $\beta_{1,2,\dots}$ and then any other quantity you want to calculate must take the form $\alpha~f(\beta_1,\beta_2,\dots)$ in general, where $\alpha$ is some combination of the original parameters which has the right units.
There are no ways to assemble any interesting unitless parameters above, so $f$ must be a constant, and the only times must all be expressible as $f~\sqrt{m/k}$ for some constant unitless number $f$. Anything else would simply not have units of time, or would take an arbitrary function of a unit-carrying parameter.
A: To go a little fundamental on the problem, we don't know whether gravity has an effect on the period or not. Clearly, for every situation that has been tested, it makes no difference, but the "equivalence principle" hasn't been tested in every regime, there's still a little wriggle-room. Essentially, we don't have a proof that the "m" in F=ma is the same "m" as the one in G=m1m2/r^2, so it's possible that different mass objects could fall at (very slightly) different accelerations in a given gravitational field. 
This is "real" physics, but at the fringe, so don't go quoting this in an exam ;)
