The length depends on the elemental damage type. I found these out by testing with Target Practice in Marcus' shop in Sanctuary.
- Fire: 5 seconds
- Shock: 2 seconds
- Corrosive: 8 seconds
- Slag: 8 seconds
This means a Corrosive gun with the same damage/second as a shock gun will deal much more damage than the shock gun if you let the effects linger. It also lets you stock a lot more Corrosive/Fire effects on a single target than you can Shock effects, but Shock effects will usually drain a shield so fast you can switch to another weapon to deal the health/armor damage instead.
Note that certain enemies resist these damage over time effects entirely, and bosses may take elemental damage for much briefer periods of time; for instance Terramorphous can only be Slagged rarely, and when it worked Slag only works for 1 second. Most normal enemies don't have shortened effect times however.