Your body makes vitamin D when your skin is exposed to the ultraviolet B (UVB) rays in sunlight. You probably need from 5 to 30 minutes of exposure to the skin on your face, arms, back or legs (without sunscreen) two times every week.
Since exposure to sunlight is a risk for skin cancer, you should use sunscreen after a few minutes in the sun, even on hazy or cloudy days.
The amount of exposure also depends on the time of the year. In the northern hemisphere, the UVB rays are more intense during the summer months and less intense during the winter months. In fact, if you live north of the 42-degree latitude, you'll have a difficult time getting enough sun exposure from November through February.
Picture a map of North America. If you live north of a line drawn on a map from the northern border of California to Boston, Massachusetts, you will probably need to get additional vitamin D from the foods you eat (or from supplements) during the winter months, even if you do go outside every day.
The intensity of UVB rays is also reduced by clouds and pollution. The UVB rays will not travel through glass so sitting next to a window will not give you enough sunlight to make vitamin D.
National Institutes of Health Office of Dietary Supplements. "Dietary Supplement Fact Sheet: Vitamin D." Updated May 2008.