We've all been there: It's close to midnight, you're vegging out to HGTV, and you're seriously craving a late-night snack. Rather than perusing the pantry for something to munch on, you're probably better off turning off the tube and getting to bed because, according to a new study, when you eat might matter just as much as what you eat.

Researchers from the University of Pennsylvania discovered that eating during so-called "rest hours" (read: late-night, typical snoozing times) can actually cause major weight gain. Researchers shifted the normal eating time of mice from night to day and watched the rodents quickly become obese. Scientists say a similar effect would happen in humans if we shift our eating patterns from day to night.

The time we eat matters because our bodies have an internal clock that tells us when we're hungry. Even just mimicking what happens when your hunger clock is broken—by eating when you should be sleeping can have the same effect as actually having a broken clock.

What's also crazy is that the mice in the study who ate during the "wrong" time gained weight even when they weren't eating more calories than the mice who followed their regular feeding schedule.

So, if you want to indulge in some leftover Halloween candy (guilty!) or a bag of chips, go for it—just as long as it's not too late.