Trainers are one of the best ways to get fit. You can do your workout without the typical distractions/obstacles found on the road. Many top riders use trainers to do their most intese work.
You can go as long or short as you like, but by far the best way to ride a trainer is to know ahead of time exactly what you are going to do.
If you have a plan and break the ride up into sections, it will be much easier mentally to deal with staring at the wall. Continuous rides over an hour are fine if you can stand them, but I would rather do 60-90 minutes of intervals and be done with it.
Let's say you have an hour to ride indoors. First, you should warm up and cool down for at least 15 minutes, so that's 30 minutes right there. That leaves 30 minutes for "work." Of course, you will need recovery between intervals so that will eat into the 30 minute work period as well. 3x5 minutes of hard "work" is 15 minutes and 3x5 minutes of recovery pedalling easy (5 min after the warmup and 2x5 min between intervals) is another 15 minutes.
That makes for a solid 60 minute workout. Only having to think for 5 minutes at a time (in this case) keeps your mind fresh instead of just pedalling for an hour without a plan. You will get fitter and faster by going harder for 5 minutes than if you rode for an hour continously also, since you can go faster for 5 minutes than you can for 60 minutes.
Trainers are best for warmups at races and for doing high-intensity interval training. They are so important, especially for racers. Even more importantly, it is not enough to simply own one.
You must know how to use a trainer to extract the full benefits they can provide. It is also extremely important to have at least one very powerful fan to cool you. If you sweat a lot with a fan on, it is not powerful enough.
Enjoy your intervals!!!