Instantly share code, notes, and snippets.

Embed
What would you like to do?
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