The difference between milk purchased cold and that on the shelf at room temperature is in how the milk was pasteurized.
Pasteurization is the process by which milk is heated to kill any bacteria that inadvertently found their way into the milk between the cow and the bottle. Milk in the refrigerator section has been heated to 72 degrees Celsius for 15 seconds then rapidly cooled and stored. Typically, pasteurized milk can be safely stored refrigerated for a few weeks before it reaches its expiration date.
Milk on a shelf has been ultra-pasteurized, heated to a much higher temperature for a much shorter time. This allows milk to remain unrefrigerated when sealed for several months before reaching its expiration date. This ultra-pasteurization kills not only bacteria but any spores that have found their way into the milk. These products are often labeled UHT for ultra-high temperature, and you may note a change in taste compared to refrigerated milk. Like all products, both products do expire. Once opened, UHT milk needs to be refrigerated and consumed within the parameters listed on the carton.