The best time to exercise is usually when the muscles are warm. By stretching, evidence suggests it can give you more power, speed and reduce the risk of injury and soreness. So before and after any forms of exercise including hiking, it is advised to stretch.
It is best to stretch daily in the morning and on return from activities. Remember to breathe deeply and allow oxygen to help your muscles, as increasing the amount of oxygen will help break down the lactic acid that causes the discomfort of a cramp. If you are prone to cramps practicing your breathing can truly help.