1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
|
#include <iostream>
#include <iomanip>
#include <cmath>
#include <ctime>
/* NAMESPACES */
using std::cout;
using std::cin;
using std::setprecision;
using std::endl;
/* START OF FUNCTION PROTOTYPS*/
/* JULIAN DAY FUNCT */
double get_julian_day (double y1, double m1, double d1)
{
if (m1 > 2) {
y1 = y1;
m1 = m1;
}
else if (m1 == 1 || m1 == 2) {
y1--;
m1+=12;
}
double a1 = floor (y1 / 100.0);
double b1 = 2 - a1 + floor (a1 / 4);
return floor (365.25 * (y1 + 4716)) + floor (30.6001 * ( m1 + 1)) + d1 + b1 - 1524.5;
}
/* DECIMAL DAY FUNCT */
double dec_time (double h, double m, double s)
{
double a = ((h * 60 * 60) + (m * 60) + s);
return (a / 86400);
}
/* END OF FUNCTION PROTOTYPS */
// SPACE
/* STARTING MAIN */
int main () {
// FUNCT PROTO
double dec, DEC; // dec time
double jd, JD; // get julian day
double M1, Y1, D1;
double MN1, S1, H1;
double Y2, M2;
double s1, mn1, h1;
double d1, y1, m1;
double HH, MM, SS;
double ajdn;
double dhm;
// SUBTRACT
double ajd;
// ACTUAL DAY
double ad, AD;
double ham;
double decimal;
/* SETTING TIME AS A VARIABLE */
/* NOTE: Program good from 1900 AD and up */
time_t rawtime;
struct tm * timeinfo;
time ( &rawtime );
timeinfo = localtime ( &rawtime );
M1 = timeinfo->tm_mon;
Y1 = timeinfo->tm_year;
D1 = timeinfo->tm_mday;
MN1 = timeinfo->tm_min;
S1 = timeinfo->tm_sec;
H1 = timeinfo->tm_hour;
Y2 = Y2 + 1900;
M2 = M2 + 1;
/* END OF TIME */
// SPACE
/* START OF UI */
cout << " ELAPSED TIME via JULIAN DAY "<< endl;
cout << " START OF PROG..." << endl;
cout << endl;
cout << endl;
// YEAR
cout << "Year: " << endl;
cout << endl;
cin >> y1;
// MONTH
cout << "Month: " << endl;
cout << endl;
cin >> m1;
// DAY
cout << "Day: " << endl;
cout << endl;
cin >> d1;
//HOUR
cout << "Hour: " << endl;
cout << endl;
cin >> h1;
//MINUTE
cout << "Minute: " << endl;
cout << endl;
cin >> mn1;
//SECOND
cout << "Second: " << endl;
cout << endl;
cin >> s1;
/* END OF UI */
// SPACE
/* START OF CALCULATIONS */
// TIME INTO DECIMAL
DEC = dec_time (h1, mn1, s1);
dec = dec_time (H1, MN1, S1);
AD = DEC + d1;
ad = dec + D1;
// JD CALCULATIONS
JD = get_julian_day (AD, m1, y1);
jd = get_julian_day (ad, M2, Y2);
// ELAPSED TIME TO DAY
ajd = JD - jd;
dhm = modf (ajd , &decimal);
HH = dhm * 24;
MM = HH * 60;
SS = MM * 60;
/* END OF CALCULATIONS */
cout << "Days: " << dhm << " Hours: " << HH << " Minutes: " << MM << " Seconds: " << SS << endl;
cin.ignore();
cin.get();
return 0;
}
|
ELAPSED TIME via JULIAN DAY
START OF PROG...
Year
1999
Month:
12
Day:
31
Hour:
23
Minute:
59
Second:
59
Days: -0 Hours: -0 Minutes: -0 Seconds: -0
|