Calculating rotation angle


I am trying to get the angle between an object and my character in 360 degrees but i couldn’t figure it out.

Basically i want to get 45 degrees on first example and 315 on second or vice versa. How should i proceed?

Thank you.