It depends on the genetics of the strain and the conditions of cultivation. Usually, cannabis requires 12 hours of uninterrupted darkness to begin flowering and will take somewhere between 6 and 8 weeks of a 12/12 light cycle to fully form flowers. There are "auto-flowering" strains that will start to flower at a particular stage of growth, regardless of the light cycle, and whose flowers will mature faster.
Indoor cultivation, where one can control the light cycle, allows growers to time their harvests or have multiple plants at different maturity stages: seedlings, vegetative, and flowering. Staggering production provides for a "perpetual harvest" where a flowering garden is always maintained. Indoor cultivation also allows for 24-hour lighting during the seedling and vegetative stage, promoting more rapid maturation of the plant than is possible under natural conditions.