Jeg fandt et php script som lavede det.
Her er en Java implementation hvis nogen ønsker at bruge det (skal gemmes i en fil ved navn Sol.java):
import java.util.*;
public class Sol {
public static void main(String[] args) {
double læng = 10.27, bred = 55.28; double GMT = 1;
System.out.println("længdegrad = "+læng);
System.out.println("breddegrad = "+bred);
System.out.println("GMT = "+GMT);
try {
System.out.println("Solopgang = "+Sol.opgang(new GregorianCalendar(), bred, læng, GMT));
System.out.println("Solnedgang = "+Sol.nedgang(new GregorianCalendar(), bred, læng, GMT));
} catch (Sol.SolException sse) {
System.out.println(sse);
}
}
public static Calendar opgang(Calendar dag, double bredde, double laengde, double GMToffset) throws SolException {
double værdi = calcSunsetORrise(dag, bredde, laengde, false, GMToffset);
int hours = (int) floor(værdi);
int minute = (int) floor(60*(værdi%1));
Calendar ret = (Calendar) dag.clone();
ret.set(Calendar.HOUR_OF_DAY, hours);
ret.set(Calendar.MINUTE, minute);
ret.set(Calendar.SECOND, 0);
ret.set(Calendar.MILLISECOND, 0);
return ret;
}
public static Calendar nedgang(Calendar dag, double bredde, double laengde, double GMToffset) throws SolException {
double værdi = calcSunsetORrise(dag, bredde, laengde, true, GMToffset);
int hours = (int) floor(værdi);
int minute = (int) floor(60*(værdi%1));
Calendar ret = (Calendar) dag.clone();
ret.set(Calendar.HOUR_OF_DAY, hours);
ret.set(Calendar.MINUTE, minute);
ret.set(Calendar.SECOND, 0);
ret.set(Calendar.MILLISECOND, 0);
return ret;
}
public static class SolException extends Exception {
public SolException(String name) {
super(name);
}
}
private static double floor(double arg) {
return arg-arg%1;
}
private static double rad(double input) { return Math.toRadians(input);}
private static double deg(double input) { return Math.toDegrees(input);}
private static double cos(double degree) { return Math.cos(rad(degree)); }
private static double sin(double degree) { return Math.sin(rad(degree)); }
private static double tan(double degree) { return Math.tan(rad(degree)); }
private static double acos(double num) { return deg(Math.acos(num)); }
private static double asin(double num) { return deg(Math.asin(num)); }
private static double calcSunsetORrise(Calendar date, double lat,
double lon, boolean sunset, double GMToffset) throws SolException {
double zenith = 90.83;
int N = date.get(Calendar.DAY_OF_YEAR);
double lonHour = lon/15;
double t;
if(sunset) t=N+((18-lonHour)/24);
else t=N+((6-lonHour)/24);
double M = (0.9856*t)-3.289;
double sinM = sin(M);
double sin2M = sin(2*M);
double L=M +(1.916*sinM) + (0.02*sin2M) + 282.634;
if(L>360) L-=360;
if(L<0) L+=360;
double tanL = 0.91764 * tan(L);
double RA = deg(Math.atan(tanL));
if(RA>360) RA-=360;
if(RA<0) RA+=360;
double LQ = (floor(L/90))*90;
double RAQ = (floor(RA/90))*90;
RA = RA + (LQ - RAQ);
RA /= 15;
double sinDec = 0.39782 * sin(L);
double cosDec = cos(asin(sinDec));
double cosH = (cos(zenith) - (sinDec * sin(lat))) / (cosDec * cos(lat));
//if cosH > 1 the sun never rises on this date at this location
//if cosH < -1 the sun never sets on this date at this location
if(cosH>1) throw new SolException("Solen står ikke op på denne dag, på denne breddegrad");
if(cosH<-1) throw new SolException("Solen er oppe hele dagen, på denne breddegrad");
double H;
if(sunset) H = acos(cosH);
else H = 360 - acos(cosH);
H /= 15;
double T = H + RA - (0.06571 * t) - 6.622;
double UT = T - lonHour;
if(UT>24) UT -= 24;
if(UT<0) UT += 24;
UT=UT+GMToffset;
if(UT<0) UT+=24;
return UT;
}
}