I can get the appropriate Julian Day portion but I am having trouble with the hours, minutes, seconds portion of Julian day. No matter what I put for hours, minutes, seconds, I dont get that part of the calculation. What am I doing wrong?
Here is the code I have so far.
Thank in advance for any help.
Jorge
Here is the code I have so far.
Code:
/**
*
* Convert a date from Calandar Date (Gregorian) to Julian, and Julian to Gregorian
*
* from https://aa.usno.navy.mil/faq/JD_formula
*
**/
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
while (!Serial){
; // wait for serial port to connect. Needed for native USB port only
}
delay(10);
Serial.print("Converting 2023-12-24 at 10:01:01 UTC to Julian Day = ");
Serial.println(String(g2j(2023, 12, 24, 10, 01, 01 )) + " \n");
}
double g2j(int year, int month, int day, int hh, int mm, int ss)
{
double JD;
double JDTime;
JD = day-32075+1461*(year+4800+(month-14)/12)/4+367*(month-2-(month-14)/12*12)/12-3*((year+4900+(month-14)/12)/100)/4;
JDTime = JD + (((hh-12)/24) + (mm/1440) + (ss/86400));
return JDTime;
}
void loop() {
// put your main code here, to run repeatedly:
}
Thank in advance for any help.
Jorge