The human body has an internal clock called the "circardian rhythm". This clock helps to control our sleep-wake cycle. Melatonin is a hormone that is secreted by the pineal gland in the brain. It maintains this sleep-wake cycle by inducing sleep at night.
Melatonin is secreted in response to sunset or darkness, thereby causing a person to feel less alert and sleepy. The blood level of this hormone increases through the night and peaks around 3am, gradually dropping to a near undetectable level by daytime.
Exposure to bright lights at night, exposure to little light in the day, jet lag and a shift job can affect the blood melatonin level, hence altering a person's sleep-wake cycle.