Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculating sunrise/sunset times in Javascript

Tags:

I have a time, and a given latitude in degrees. Is there any method of calculating the time of sunrise and sunset in Javascript with this information?

like image 264
Xcqtion Avatar asked Sep 22 '13 21:09

Xcqtion


People also ask

How do you calculate sunrise and sunset?

Sunrise/Sunset Calculations where the positive number corresponds to sunrise, negative to sunset. Then the UTC time of sunrise (or sunset) in minutes is: sunrise = 720 – 4*(longitude + ha) – eqtime where longitude and hour angle are in degrees and the equation of time is in minutes.

How do you calculate the number of hours of daylight?

How do I calculate daylight hours? Multiply 2 by the sunrise or sunset angle. Divide the product with 15 to get the daylight hours.

How is Sun set calculated?

How are the times of sunset and sunrise determined? A. Sunset and sunrise have exactly the same definition: the time when the apparent uppermost ray of the Sun is on the astronomical horizon. If it is the first ray, it is sunrise and if it is the last ray, it is sunset.


1 Answers

SunCalc seems to do what you want

SunCalc is a tiny BSD-licensed JavaScript library for calculating sun position, sunlight phases (times for sunrise, sunset, dusk, etc.), moon position and lunar phase for the given location and time

https://github.com/mourner/suncalc

like image 160
Epeli Avatar answered Sep 26 '22 12:09

Epeli