not only losing weight, working out helps u maintain a healthy lifestyle lol, its a lifelong habit :]
~
the thing about working out is:
when u do resistance training or weight training, ur building muscle by tearing up existing muscle tissues, whereas if you were doing cardio, ur burning calories/fat/muscle. one builds, other destroys**
you sound fairly new to the fitness world, so most people are in the gym least a hour or so. depending on what routines they do.
if u were in the gym for more than 2 hours, i'd say you probably do not know where your doing, and thus ur wasting ur time. &
the key factor to working out is also a healthy intake of food, u need to stop eating junk food and WATCH your caloric intake. depending on your body type = height/weight
and answering your question, 20 minutes, to 1 hour in the gym, it mostly depends on what work out routine your aiming for.
so what workouts are you planning on doing while your at the gym?