Marijn
Active member
For my current project, I need to convert J2000 datetime's to MJD.
I've found the javascript funtion below. But it does not include a time, only the date. The math is confusing me. Can anybody help me to alter this code so it will output a full MJD?
I've found the javascript funtion below. But it does not include a time, only the date. The math is confusing me. Can anybody help me to alter this code so it will output a full MJD?
Code:
function J2000_to_YMD(t) {
// Convert seconds past J2000 to (Year,Month,Day)
var j,dg,c,dc,db,a,da,m, YMD = [];
j = Math.floor(2451545 + t/86400 + 0.5) + 32044;
dg = j % 146097;
c = Math.floor((Math.floor(dg/36524) + 1)*3/4);
dc = dg - c*36524;
db = dc % 1461;
a = Math.floor((Math.floor(db/365) + 1)*3/4);
da = db - a*365;
m = Math.floor((da*5 + 308)/153) - 2;
YMD[0] = Math.floor(j/146097)*400 + c*100 + Math.floor(dc/1461)*4 + a - 4800 + Math.floor((m + 2)/12);
YMD[1] = (m + 2) % 12 + 1;
YMD[2] = da - Math.floor((m + 4)*153/5) + 123;// + JD%86400;
return YMD;
}