Eric said:
Sat Feb 21 21:10:01 2009 equates to 1,235,279,401 which is about
366 times what it should be if i am calculating this right
39 years * 86400 seconds should be about 3,369,600
You really can't believe that a year is only one day long.
In addition to thinking that a day and a year are the same thing,
your
printf("%ld\n", (long) mktime(&tm));
carries several assumptions without basis in the C language.
See below:
#include <stdio.h>
#include <time.h>
#include <float.h>
int main(void)
{
time_t then_value, now_value;
struct tm then_struct, now_struct;
double dt;
then_struct.tm_sec = 0;
then_struct.tm_min = 0;
then_struct.tm_hour = 0;
then_struct.tm_mday = 1;
then_struct.tm_mon = 0;
then_struct.tm_year = 1970 - 1900;
then_struct.tm_isdst = -1;
now_struct.tm_sec = 1;
now_struct.tm_min = 10;
now_struct.tm_hour = 21;
now_struct.tm_mday = 21;
now_struct.tm_mon = 1;
now_struct.tm_year = 2009 - 1900;
now_struct.tm_isdst = -1;
printf("Values in then_struct before calling mktime()\n"
"\"%d/%02d/%d %2d:%02d:%02d DST %d\"\n\n",
then_struct.tm_mon, then_struct.tm_mday, then_struct.tm_year,
then_struct.tm_hour, then_struct.tm_min, then_struct.tm_sec,
then_struct.tm_isdst);
printf("Values in now_struct before calling mktime()\n"
"\"%d/%02d/%d %2d:%02d:%02d DST %d\"\n\n",
now_struct.tm_mon, now_struct.tm_mday, now_struct.tm_year,
now_struct.tm_hour, now_struct.tm_min, now_struct.tm_sec,
now_struct.tm_isdst);
#if 0
printf("%ld\n", (long) mktime(&tm));
/* There is no reason at all to expect that a now_t is any
human-interpretable meaning. To suggest that it represents seconds
is assuming an implementation-specific detail, as it is to suggest
that the epoch is Jan 1, 1970, or even that the values stored are
linear. */
#endif
then_value = mktime(&then_struct);
now_value = mktime(&now_struct);
printf("Values in then_struct after calling mktime()\n"
"\"%d/%02d/%d %2d:%02d:%02d DST %d\"\n",
then_struct.tm_mon, then_struct.tm_mday, then_struct.tm_year,
then_struct.tm_hour, then_struct.tm_min, then_struct.tm_sec,
then_struct.tm_isdst);
printf("This corresponds to %s\n", ctime(&then_value));
printf("Values in now_struct after calling mktime()\n"
"\"%d/%02d/%d %2d:%02d:%02d DST %d\"\n",
now_struct.tm_mon, now_struct.tm_mday, now_struct.tm_year,
now_struct.tm_hour, now_struct.tm_min, now_struct.tm_sec,
now_struct.tm_isdst);
printf("This corresponds to %s\n", ctime(&now_value));
printf("difftime reports that there is a %.*g second difference\n"
"between then and now.\n", DBL_DIG, dt =
difftime(now_value, then_value));
printf("That corresponds to %.*g days, \n"
"based on a 86400 sec day (rather than 86400.0028)\n",
DBL_DIG, dt /= 86400.);
printf("or %.*g equinoctial (tropical) years,\n"
"or %.*g anomalistc years,\n"
"or %.*g sidereal years,\n"
"or %.*g Gaussian years,\n"
"or %.*g Julian years.\n",
DBL_DIG, dt / 365.2421897,
DBL_DIG, dt / 365.259635,
DBL_DIG, dt / 365.256363,
DBL_DIG, dt / 365.25690, DBL_DIG, dt / 365.25);
return 0;
}
Values in then_struct before calling mktime()
"0/01/70 0:00:00 DST -1"
Values in now_struct before calling mktime()
"1/21/109 21:10:01 DST -1"
Values in then_struct after calling mktime()
"0/01/70 0:00:00 DST 0"
This corresponds to Thu Jan 1 00:00:00 1970
Values in now_struct after calling mktime()
"1/21/109 21:10:01 DST 0"
This corresponds to Sat Feb 21 21:10:01 2009
difftime reports that there is a 1235250601 second difference
between then and now.
That corresponds to 14296.8819560185 days,
based on a 86400 sec day (rather than 86400.0028)
or 39.1435665407701 equinoctial (tropical) years,
or 39.1416969904668 anomalistc years,
or 39.1420476253784 sidereal years,
or 39.1419900788144 Gaussian years,
or 39.14272951682 Julian years.