To convert Gregorian date (D,M,Y) |
I don't need to convert back to gregorian calender date I need to find elapsed time between dates
1. take the time and the date into an int. Like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
#include <iostream>
using namespace std;
/* Global Vars. */
// \/ year month day
int y = 1996;
int m = 03;
int d = 31; // day month year
// \/ hour minute second
int h = 23;
int mn = 59;
int s = 59;
int jdn1 , jdn2;
double tod; // time of day
double sec // dividing tod by seconds in a day to come up with a fractional julian day
| |
and convert into a julian day:
1 2 3
|
jdn1 = (1461 * (Y + 4800 + (M - 14)/12))/4;
jdn2 = jdn1 + (367 * (M - 2 - 12 * ((M - 14)/12)))/12 - (3 * ((Y + 4900 + (M - 14)/12)/100))/4 + D - 32075;
/* above caculated julian date with correct user input; */
| |
and turn it into a fractional day
1 2 3 4 5 6 7 8 9
|
/* finding the amount of seconds elapsed in that day */
tod = (H * 3600) + (MN * 60) + S;
/* turning it into a fractional day */
sec = TOD1/86400;
/* adding back jdn 2 to sec because that was an int */
out = jdn2 + sec;
| |
Do this with 2 dates and store both as a variable...
And subtract i.e
today's julian date is
2455217.17222
and the julian date computed above
would be
2450174.49999
so
2455217.17222 - 2450174.49999 = 5042.67223
so what I am asking is how to convert that to elapsed time (in julian days [i.e 5042.67223]) 100% accurately in compliance with leap years.
and are those formulas I used to convert those dates compliant with leap years.
And when I subtract the two dates (if all of the math was compliant with leap years) how do I make a number like 5042.67223 into elapsed time.
With a format like Years, Months, Days, Hours, Minutes, Seconds.
I have formulas to get the week day, minutes, seconds, and hours.
But this will all get thrown off it even One formula isn't leap year compliant.
Buffbill - Ive googled and googled and I can't find any thing to help me because looks like this has only been done in languages like java and ?php? and all the java source code is messed up i.e no formulas.
So a little help?
NOTE: I shortened my julian day formula so maybe you guys could read it better.