Convert regular date and time to Julian date and vice versa
- by zbz.lvlv
I am currently working on a program that will calculate sunrise and sunset times. How do I convert yyyymmddhhmmss to Julian date? I need the date to be very precise. It'll great if there can be an example for such conversions.
Calendar cNow = Calendar.getInstance();
Calendar cJan1 = Calendar.getInstance();
double julianJan1_2014_12_00_00 = 2456659;
cJan1.set(2014, 0, 0, 12, 0);
Date dJan1 = cJan1.getTime();
Date dNow = cNow.getTime();
long lJan1 = dJan1.getTime();
long lNow = dNow.getTime();
double diffDay = (lNow - lJan1) / 1000 / 60 / 60 / 24;
double julianDate = diffDay + julianJan1_2014_12_00_00;
The code I currently have.