Reputation: 11628
I need to get the julian day of an arbitrary date in javascript (it should work for about +-50 years from now) for calculating the position of the sun. What is the easisest way in javascript to get that number, or is there already a method? Thank you
SOLVED: sdespont posted a good link
Upvotes: 0
Views: 698
Reputation: 2261
When I first wanted to know about finding sunrise and sunset times I was looking for answers on wikipedia but I'm no math wizard. I couldn't understand the formula, well maybe just a little. I knew that you needed to be able to iterate something from 0 to whatever the limit was. But what I had found outside of those was a web page to calculate the very formula that I had been seeing in Greek. Here is that web page. Looking at examples is not stealing in my mind. There are many other sites similar to this on the net. Some use Javascript others use Perl and PHP.
<img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/45e26774ace10d6eb58299c5adcab50958a53d61" class="mwe-math-fallback-image-inline mw-math-element" aria-hidden="true" style="vertical-align: -2.505ex; width:70.501ex; height:6.176ex;" alt=" J\!D\!N = \text{day} + \left\lfloor\frac{153m+2}{5}\right\rfloor + 365y+ \left\lfloor\frac{y}{4}\right\rfloor - \left\lfloor\frac{y}{100}\right\rfloor + \left\lfloor\frac{y}{400}\right\rfloor - 32045 " />
Upvotes: 1