Transforming business operations through innovation

Developer Blog

Tips and tricks for developers.

Determine the Time of Day From the Sun's Azimuth in C#

The latest release of CoordinateSharp allows users to determine the time of day based on a coordinate, date, and the azimuth of the sun. This feature can be a great tool for solar panel efficiency tracking.

//Create a coordinate and specify a date.
Coordinate c = new Coordinate(49, -122, new DateTime(2023, 9, 30));

//Set local UTC offset as desired.
c.Offset = -7;
 
//Set current sun azimuth in degrees E of N
double az = 120;

//Determine time of day. Default azimuth accuracy error delta is 1 degree by default, 
//but it is set at .5 for this example.
DateTime? t = Celestial.Get_Time_At_Solar_Azimuth(az, c, .5);
           
Console.WriteLine($"{t}"); //9/30/2023 9:21:44 AM

Determining the time of day from the sun's azimuth will return a nullable DateTime value. When a null value is returned, it means the sun is either down/set (too inaccurate to reliably return a value) OR the azimuth provided did not occur within the specified date / error delta.

Justin Gielski