Navy-12 weeks Pensacola, FL
Coast Guard-17 weeks, New London CT
Rough estimate but about 30% of officers come from OCS programs, rest from ROTC or service academies. After completing any military flight training program the FAA awards you a Commercial Pilot equivalency after passing a written exam.
Service obligation AFTER completing flight school is 6-8 years depending on service.