Currently, at least 8 years if one includes the reserve duty, although active duty may be as low as 2 years in some cases. Many of the veteran examples are of non-traditional student age.
Also, some who are enlisted in military service apply and are admitted to the academies.
For obvious reasons, enlisted military service is not normally a pre-planned gap activity in the “upper-class” sense as usually discussed on these forums.