For a solar-type star, the formation time is about 10 million years; for more massive stars, it takes about 100,000 years.
A solar-type star forms in about 10 million years. The first phase is the gravitational collapse of an interstellar gas cloud. The timescale for this collapse depends on the density of the object. When a central object is formed in a hydrostatic equilibrium, the core will contract without heat transfer (adiabatically) till a temperature of about 2000 K is reached, which then leads to the second phase of collapse, leading to the formation of the protostar itself. It takes about 1000 years to get to this stage, from the hydrostatic core.
The next stage, the protostellar phase, is mostly an accretion phase. It takes about 200,000 years to accrete 90% of the final mass of the star.
Since the star is still contracting, the temperature at its center is increasing. When a temperature of 1 million K is reached, the protostar contracts and radiates away its gravitational energy. Temperature continues to rise, up to 10 million K, when hydrogen eventually starts to burn, which leads to the birth of the star. It takes around 10 million years to get to this stage.
For massive stars, the above process is much faster, and different. It takes about 100,000 years to form a massive star.