
Math & Physics Mathematical and physical problems of space flight and astronomy. 

Thread Tools 
11122018, 12:32 PM  #1 
Orbinaut

J2000 datetime to MJD
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? 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; } 
11122018, 02:51 PM  #2 
Orbinaut

The Modified Julian Date is a continuous count of days since midnight UTC at the beginning of November 17, 1858 (in the Gregorian calendar).
The J2000.0 TT offset (ΔtJ2000) is a continuous count of days since noon TT on January 1, 2000. So  to convert J2000 to MJD, all you need to do is find the MJD for 1/1/2000 at noon (which the date.exe tool supplied with orbiter can easily do  here's a hint: 51544.500000), then to convert j2000 to MJD simply add that value (51544.500000) to your J2000 value. Last edited by bcbarnes; 11122018 at 03:06 PM. 
11122018, 04:04 PM  #3 
Orbinaut

Thanks. An example of the value I want to convert is 660787200. These are seconds after Jan 1st 2000 at noon.
(660787200/86400) + 51544.5 = 59093.5. Does that seem right? The examples I found all look a lot more complicated. 
11122018, 05:05 PM  #4 
Orbinaut

MJD 59093.5 according to the orbiter utility "date.exe" is Sept. 1, 2020. Is that what you where hoping for? If so, you got it right.

11122018, 06:23 PM  #5 
Orbinaut

660787200 should correspond with Dec092020. That's the output of the FormatDate function posted above, which I took from this Nasa site: https://trajbrowser.arc.nasa.gov/javascript/traj_lib.js
So the formula does not work (yet). Any other suggestions are very welcome. I can break my head on these things.. 
11122018, 09:14 PM  #6 
Orbinaut

Actually, it was the math above that is the problem:
660787200/86400 = 7648 days 51544.5 + 7648 = 59192.5, not 59093.5 59192.5 = Dec 9, 2020  as expected. Sorry I didn't catch this before. 
11122018, 09:39 PM  #7 
Orbinaut

Quote:
Last edited by Marijn; 11122018 at 09:43 PM. 
11122018, 10:21 PM  #8 
Orbinaut

No worries. Just repaying all the help I've received here.


Thread Tools  


Quick Links  Need Help? 