Every case is different. However, for optimum long-term dental health and results, make sure to wear them for the first 6 weeks for 20-22 hours a day. After that, try wearing them only while you sleep. If they start feeling tight on your teeth, it means your teeth are starting to shift, and you need to wear the retainers for longer periods. If they don't feel tight, you can try wearing them for shorter periods of time.
Overall, eventually most people only need to wear them every night, while others will only need to wear them for limited periods of time. Some people find that unless they wear retainers all day, every day, their teeth will always want to move back to their previous positions. If after 6-12 months, you find that your teeth are still moving when you don't wear your retainer, you may wish to see your regular dentist or orthodontist to get a permanent retainer made (or a removable, but more 'heavy duty' one). These tend to last longer than the plastic trays, so if you're going to be wearing them forever, they might be a better choice.