It takes millions of years to form a star.Why?
It takes about 10 million years for a gas cloud to form a star.
Stars start out as clouds of gas and dust. Once the cloud gets massive enough through combining with more gas or shock waves from a supernova, it starts to collapse under gravity.
After about 1,000 years a ball of gas form in the cloud called a protostar. More and more gas and dust falls into the protostar. It is a slow process which takes about 200,000 years to gain most of the mass of the final star.
Next, the protostar starts to collapse and heat up until it is hot enough for Hydrogen fusion to start. This takes about 10 million years.
It takes a long time for a diffuse gas cloud to collapse and heat up to become a star. It is about 10 million years for a star like our Sun. More massive stars form more quickly, maybe in 100,000 years.