Orbiter-Forum J2000 datetime to MJD
 Register Blogs Orbinauts List Social Groups FAQ Projects Mark Forums Read

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

 11-12-2018, 12:32 PM #1 Marijn 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; }```
 11-12-2018, 02:51 PM #2 bcbarnes 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; 11-12-2018 at 03:06 PM.
 11-12-2018, 04:04 PM #3 Marijn 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.
 11-12-2018, 05:05 PM #4 bcbarnes 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.
 11-12-2018, 06:23 PM #5 Marijn Orbinaut 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..
 11-12-2018, 09:14 PM #6 bcbarnes 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.
 11-12-2018, 09:39 PM #7 Marijn Orbinaut Quote: Originally Posted by bcbarnes  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.
 11-12-2018, 10:21 PM #8 bcbarnes Orbinaut No worries. Just repaying all the help I've received here.

 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 User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home Orbiter-Forum.com     Announcements     Meets & Greets Orbiter Space Flight Simulator     Orbiter Web Forum         OFMM         Orbiter Forum Space Station         Simpit Forum     General Questions & Help     MFD Questions & Help     Hardware & Software Help     Tutorials & Challenges     Orbiter SDK     Orbiter Visualization Project     Orbiter Beta » Orbiter Project Orbiter Addons     OrbitHangar Addons & Comments     Addons     Addon Development     Addon Requests     Addon Support & Bugs         Addon Developer Forums             Project Apollo - NASSP     Orbiter Lua Scripting Far Side of the Moon     Spaceflight News     Math & Physics     Astronomy & the Night Sky     Backyard Rocketry     Brighton Lounge     International Forum

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