Is it okay to get vitamin D from sunshine for 30 minutes to treat my anxiety?

In the morning whenever there's sunshine around 8 am-9 am before 10 am I stay outside for 30 minutes directly from sun to get vitamin d to treat my anxiety and depression. I read sunlight can give vitamin d which can treat anxiety and can improve mood and can make you immune to some diseases like cancer. Does staying in the sun can really treat my anxiety and improve my mood?
Is it okay to get vitamin D from sunshine for 30 minutes to treat my anxiety?
Post Opinion