Orbiter-Forum  

Go Back   Orbiter-Forum > Far Side of the Moon > Math & Physics
Register Blogs Orbinauts List Social Groups FAQ Projects Mark Forums Read

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

Reply
 
Thread Tools
Old 11-12-2018, 12:32 PM   #1
Marijn
Orbinaut
 
Marijn's Avatar
Default 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;
}
Marijn is offline   Reply With Quote
Old 11-12-2018, 02:51 PM   #2
bcbarnes
Orbinaut
 
bcbarnes's Avatar
Default

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; 11-12-2018 at 03:06 PM.
bcbarnes is offline   Reply With Quote
Old 11-12-2018, 04:04 PM   #3
Marijn
Orbinaut
 
Marijn's Avatar
Default

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.
Marijn is offline   Reply With Quote
Old 11-12-2018, 05:05 PM   #4
bcbarnes
Orbinaut
 
bcbarnes's Avatar
Default

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 is offline   Reply With Quote
Old 11-12-2018, 06:23 PM   #5
Marijn
Orbinaut
 
Marijn's Avatar
Default

660787200 should correspond with Dec-09-2020. 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..
Marijn is offline   Reply With Quote
Old 11-12-2018, 09:14 PM   #6
bcbarnes
Orbinaut
 
bcbarnes's Avatar
Default

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.
bcbarnes is offline   Reply With Quote
Old 11-12-2018, 09:39 PM   #7
Marijn
Orbinaut
 
Marijn's Avatar
Default

Quote:
Originally Posted by bcbarnes View Post
 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 by Marijn; 11-12-2018 at 09:43 PM.
Marijn is offline   Reply With Quote
Old 11-12-2018, 10:21 PM   #8
bcbarnes
Orbinaut
 
bcbarnes's Avatar
Default

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

bcbarnes is offline   Reply With Quote
Reply

  Orbiter-Forum > Far Side of the Moon > Math & Physics


Thread Tools

Posting Rules
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Jump


All times are GMT. The time now is 05:49 PM.

Quick Links Need Help?


About Us | Rules & Guidelines | TOS Policy | Privacy Policy

Orbiter-Forum is hosted at Orbithangar.com
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.
Copyright 2007 - 2017, Orbiter-Forum.com. All rights reserved.