Based on: http://williams.best.vwh.net/sunrise..._algorithm.htmCode:<html> <head> <title>Sunrise and sunset</title> <script type="text/javascript"> function sunupdown(longitude, ew, latitude, ns, localoffset){ var d = new Date(); var dyear = d.getUTCFullYear(); var dmonth = d.getUTCMonth(); var dday = d.getUTCday(); var zenith = 90.83; var lnghour = longitude / 15; var n1, n2, n3, n, t1, t2, m1, m2, l1, l2, ra1, ra2, lquadrant1, lquadrant2, raquadrant1, raquadrant2; var sindec1, sindec2, cosdec1, cosdec2, cosh1, cosh2, h1, h2, T1, T2, UT1, UT2, localT1, localT2; var output = " ", output1 = " ", output2 = " "; // Set coords as negative if West or South. if(ew == 'w' || ew == 'W'){longitude -= (2*longitude);} if(ns == 's' || ew == 'S'){latitude -= (2*latitude);} // Calculate the day of the year. n1 = Math.floor(275 * dmonth / 9); n2 = Math.floor((dmonth + 9) / 12); n3 = (1 + Math.floor((dyear - 4 * Math.floor(dyear / 4) + 2) / 3)); n = n1 - (n2 * n3) + dday - 30; // Get sunrise and sunset times. t1 = n + ((6 - lnghour) / 24); t2 = n + ((18 - lnghour) / 24); // Sun's mean anomaly. m1 = (0.9856 * t1) - 3.289; m2 = (0.9856 * t2) - 3.289; // Sun's true longitude. l1 = m1 + (1.916 * Math.sin(m1)) + (0.020 * Math.sin(2 * m1)) + 282.634; if(l1 < 0){l1 += 360;} if(l1 > 360){l1 -= 360;} l2 = m2 + (1.916 * Math.sin(m2)) + (0.020 * Math.sin(2 * m2)) + 282.634; if(l2 < 0){l2 += 360;} if(l2 > 360){l2 -= 360;} // Sun's right ascension. ra1 = Math.atan(0.91764 * Math.tan(l1)); if(ra1 < 0){ra1 += 360;} if(ra1 > 360){ra1 -= 360;} ra2 = Math.atan(0.91764 * Math.tan(l2)); if(ra2 < 0){ra2 += 360;} if(ra2 > 360){ra2 -= 360;} // Sun's quadrant. lquadrant1 = (Math.floor(l1/90)) * 90; raquadrant1 = (Math.floor(ra1/90)) * 90; ra1 = ra1 + (lquadrant1 - raquadrant1); lquadrant2 = (Math.floor(l2/90)) * 90; raquadrant2 = (Math.floor(ra2/90)) * 90; ra2 = ra2 + (lquadrant2 - raquadrant2); // Convert right ascension into hours. ra1 = ra1 / 15; ra2 = ra2 / 15; // Get sun's declination. sindec1 = 0.39782 * Math.sin(l1); sindec2 = 0.39782 * Math.sin(l2); cosdec1 = Math.cos(Math.asin(sindec1)); cosdec2 = Math.cos(Math.asin(sindec2)); // Sun's local hour angle. cosh1 = (Math.cos(zenith) - (sindec1 * Math.sin(latitude))) / (cosdec1 * Math.cos(latitude)); cosh2 = (Math.cos(zenith) - (sindec2 * Math.sin(latitude))) / (cosdec2 * Math.cos(latitude)); if(cosh1 > 1){output1 = "No sunrise.";} if(cosh2 < -1){output2 = "No sunset.";} // Get hour. h1 = 360 - Math.acos(cosh1); h2 = Math.acos(cosh2); h1 = h1 / 15; h2 = h2 / 15; // Local mean time for rise and set. T1 = ra1 - (0.06571 * t1) - 6.622; T2 = ra2 - (0.06571 * t2) - 6.622; // Adjust back to UTC. UT1 = T1 - lnghour; if(UT1 < 0){UT1 += 24;} if(UT1 > 24){UT1 -= 24;} UT2 = T2 - lnghour; if(UT2 < 0){UT2 += 24;} if(UT2 > 24){UT2 -= 24;} // Convert UTC value to local based on longitude and latitude. localT1 = UT1 + localoffset; localT2 = UT2 + localoffset; // Output sunrise and sunset times as a string. if(output1 != " "){localT1 = output1;} if(output2 != " "){localT2 = output2;} document.write("<p>Sunrise: "+localT1+"<br>Sunset: "+localT2+"</p>"); } </script> </head> <body> <h1>Sunrise and sunset at location X.</h1> <script type="text/javascript">sunupdown(50, 'e', 50, 's', 5);</script> </body> </html>

Basically it's not working yet, and I'd appreicate any help. There's no output, and I'm not sure why. @_@