If you can swim outside for about 10 to 15 minutes, two or three times a week, you're all set, because that's how much sun it takes to produce the vitamin D you need – about 10,000 to 15,000 IU in each session.
This is based on a UV index of 7, around the midday UV index in spring in hotter places such as Australia or summer in cooler places such as the UK.
If the UV index is 14, you'll need half the time to produce the same amount of vitamin D, and if it's just 3, you'll need twice the time.
The right dose of sun is just short of getting some color in the skin on each occasion. This amount of whole body sun exposure generates the maximum amount of vitamin D possible.
Longer exposure won't produce more vitamin D, but it may raise the risk of other diseases, particularly skin cancer.
Exposing a smaller area for more time doesn't work, because once all the vitamin D in a given area of skin is made (within 15 minutes or so), no more is made until the chemical in the skin is formed again, which takes about a day. This amount of exposure is very safe.