Tens of millions of years
Gathering most of the mass takes only about 100,000 years, but the young star then keeps slowly contracting and heating before fusion fully stabilizes it. From the first collapse to a steady star on the main sequence takes on the order of tens of millions of years.