public class HelloWorld | |
{ | |
public static void main(String[] args) | |
{ | |
PracticalAstronomy astro = new PracticalAstronomy(2455002.25); | |
double[] date = astro.getGregorianDay(); | |
System.out.print((int)date[0] + " " + (int)date[1] + " " + date[2]); | |
//will output 2009 6 19.75 | |
} | |
} | |
// Public class Practical Astronomy | |
public class PracticalAstronomy | |
{ | |
private double jd; | |
public PracticalAstronomy(double jd) | |
{ | |
this.jd = jd; | |
} | |
public double[] getGregorianDay() | |
{ | |
jd = jd + 0.5; | |
double I = (int)jd; | |
double F = jd - I; | |
double A = (int)((I - 1867216.25)/36524.25); | |
double B = I > 2299160 ? I + A - (int)(A / 4) + 1 : I; | |
double C = B + 1524; | |
double D = (int)((C-122.1) / 365.25); | |
double E = (int)(365.25 * D); | |
double G = (int)((C-E)/30.6001); | |
double d = C - E + F - (int)(30.6001 * G); | |
double m = G < 13.5 ? G - 1 : G - 13; | |
double y = m > 2.5 ? D - 4716 : D - 4715; | |
return new double[] {y,m,d}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment