J2000 datetime to MJD

Marijn

Active member
Joined
Mar 5, 2008
Messages
755
Reaction score
166
Points
43
Location
Amsterdam
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;
}
 

bcbarnes

Member
Joined
Nov 17, 2017
Messages
57
Reaction score
0
Points
6
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:

Marijn

Active member
Joined
Mar 5, 2008
Messages
755
Reaction score
166
Points
43
Location
Amsterdam
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.
 

bcbarnes

Member
Joined
Nov 17, 2017
Messages
57
Reaction score
0
Points
6
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.
 

bcbarnes

Member
Joined
Nov 17, 2017
Messages
57
Reaction score
0
Points
6
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.
 

Marijn

Active member
Joined
Mar 5, 2008
Messages
755
Reaction score
166
Points
43
Location
Amsterdam
59192.5 = Dec 9, 2020 - as expected.

Thanks! I did enter 59093.5 in the date.exe as well to check and missed my own error again. How stupid of me. Sorry for that.
 
Last edited:

bcbarnes

Member
Joined
Nov 17, 2017
Messages
57
Reaction score
0
Points
6
No worries. Just repaying all the help I've received here.

:cheers:
 
Top