Last active
July 15, 2018 08:41
-
-
Save alfannas/1f9e0f797572f294a67509f9c630199d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ShowJulianDay | |
{ | |
// arguments are passed using the text field below this editor | |
public static void main(String[] args) | |
{ | |
PracticalAstronomy astro = new PracticalAstronomy(2009,6,19,18,0,0); | |
System.out.print(astro.getJulianDay()); | |
} | |
} | |
public class PracticalAstronomy | |
{ | |
private int year; | |
private int month; | |
private int day; | |
private int hour; | |
private int minute; | |
private int second; | |
public PracticalAstronomy(int year,int month,int day,int hour,int minute,int second) | |
{ | |
this.year = year; | |
this.month = month; | |
this.day = day; | |
this.hour = hour; | |
this.minute = minute; | |
this.second = second; | |
} | |
public double getJulianDay() | |
{ | |
boolean julian = true; | |
if (year < 1582 || (year == 1582 && month <= 10) || (year == 1582 && month == 10 && day < 15)) julian = false; | |
int D = day; | |
int M = month; | |
int Y = year; | |
if (M < 3) | |
{ | |
Y--; | |
M += 12; | |
} | |
int A = Y / 100; | |
int B = julian ? 2 - A + A / 4 : 0; | |
int C = Y < 0 ? (int)((365.25 * Y) - 0.75) : (int)(365.25 * Y); | |
int F = (int)(30.6001 * (M + 1)); | |
double dayFraction = (hour + (minute + (second / 60.0)) / 60.0) / 24.0; | |
double jd = B + C + F + D + dayFraction + 1720994.5; | |
return jd; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment