Massive stars (with mass m* > 8 solar masses M☉) are fundamental to the evolution of galaxies, because they produce heavy elements, inject energy into the interstellar medium, and possibly regulate the star formation rate. The individual star formation time, t*f, determines the accretion rate of the star; the value of the former quantity is currently uncertain by many orders of magnitude, leading to other astrophysical questions. For example, the variation of t*f with stellar mass dictates whether massive stars can form simultaneously with low-mass stars in clusters. Here we show that t*f is determined by the conditions in the star's natal cloud, and is typically ~105yr. The corresponding mass accretion rate depends on the pressure within the cloud-which we relate to the gas surface density-and on both the instantaneous and final stellar masses. Characteristic accretion rates are sufficient to overcome radiation pressure from ~100M☉ protostars, while simultaneously driving intense bipolar gas outflows. The weak dependence of t*f on the final mass of the star allows high- and low-mass star formation to occur nearly simultaneously in clusters.