Correct. Perhaps even more important than vitamin D is nitric oxide. The summarised advice is to avoid the sun when it is high in the sky (noon-ish), get some sun in the mornings/evenings, and supplement vitamin D. This ensures good levels of vitamin D and nitric oxide while reducing skin cancer risk.
Details here: https://youtu.be/Kvh4D_osFXs