Caffiene can stay in the body for 10 hours, assuming that your liver is not backed up trying to process alchohol and other toxin. [reference]
Arguably, your liver is one of the most over-worked organs in the body. It has to detoxify all the toxins that is coming in day and night. Caffiene needs to be detoxify by the liver as well.
Caffiene in tea is less problematic than caffiene in coffee. That is because tea contains L-theanine, which according to Life Extension, “L-theanine neutralizes the speedy, jagged, bad effects of caffeine without reducing its mind-energizing, fat-burning features”.
In fact, L-theanine is found in many sleep aids.