C# Sunrise/Sunset with latitude/longitude

I know this post is old, but in case anyone is still looking…

CoordinateSharp is available as a Nuget package. It’s a standalone packge that can handle sun as well as moon times.

Celestial cel = Celestial.CalculateCelestialTimes(85.57682, -70.75678, new DateTime(2017,8,21));
Console.WriteLine(cel.SunRise.Value.ToString());

Note:

It assumes DateTimes are always in UTC.

Lastly, you may need to reference the Celestial objects Sun/Moon .Condition if a date returns null. This occurs when the sun is up/down all day.

EDIT 1/9/2019

The library has changed dramatically since this post. It can now handle local times as well.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)