I’ve been wondering this myself as milk we buy at Kroger goes bad in a week whereas milk from Whole Foods lasts a month. Turns out the pasteurization process is different for the two types of milk.
The process that gives the milk a longer shelf life is called ultrahigh temperature (UHT) processing or treatment, in which milk is heated to 280 degrees Fahrenheit (138 degrees Celsius) for two to four seconds, killing any bacteria in it.
Compare that to pasteurization, the standard preservation process. There are two types of pasteurization: “low temperature, long time,” in which milk is heated to 145 degrees F (63 degrees C) for at least 30 minutes*, or the more common “high temperature, short time,” in which milk is heated to roughly 160 degrees F (71 degrees C) for at least 15 seconds.