"Gordon Burditt" <go***********@burditt.org.org> wrote:
One possible representation of time_t is:
hhHHSSMMmmddyyyy
substitute decimal digits for the values, then treat it as a decimal
integer. A time_t needs more than 48 bits for this representation.
yyyy = year (Y10K problem here!!)
mm = month (1-12)
dd = day of month (1-31)
HH = hour (0-24)[*]
MM = minute (0-60)[*]
SS = second (0-60)[*]
hh = hundredths of seconds (0-99)
typedef long long time_t;
double difftime(time_t a, time_t b)
{
double year = (a % 10000
- b % 10000) * 31556952.0;
double month = (a % 100000000 / 1000000
- b % 100000000 / 1000000) * 2629746.0;
double day = (a % 1000000 / 10000
- b % 1000000 / 10000) * 86400.0;
double hour = (a % 100000000000000 / 1000000000000
- b % 100000000000000 / 1000000000000) * 3600.0;
double minute = (a % 10000000000 / 100000000
- b % 10000000000 / 100000000) * 60.0;
double second = (a % 1000000000000 / 10000000000
- b % 1000000000000 / 10000000000);
double hundredth = (a / 100000000000000
- b / 100000000000000) / 100.0;
return year + month + day + hour + minute + second + hundredth;
}
The values for month and year are for an average year, but they should
actually depend on the year in question. Argh!
--
Simon.