Time Info
Lars Wirzenius
wirzeniu at klaava.Helsinki.FI
Sun May 26 18:48:09 AEST 1991
In article <39 at neis.UUCP> molnar at neis.UUCP (Christopher Molnar) writes:
>I am writing a C routine that needs to compare a start time and
>the current time and have the result in minute.
>
>Can any-one suggest where to find this in the Xenix reffereance manuals
>or suggest a way I can accomplish this?
The standard library function difftime returns the difference in seconds
between two times (represented as time_t's, i.e. whatever time()
returns). This is easy to convert to minutes:
time_t then, now;
double secs, mins; /* difftime returns
* double
*/
time(&then);
.....
time(&now);
secs = difftime(then, now);
mins = secs / 60.0; /* you could do some
* rounding here, if you
* prefer
*/
Oops. I just checked my manuals for Xenix, and it seems that it
doesn't have difftime. :-(
In that case one needs to take advantage of the fact that time_t on SCO
Xenix (and most of the Unix world) is a long that tells the seconds
since the beginning of the Era (January 1, 1970, at 00:00:00 GMT), so
the difftime can be replaced by
secs = (double) (now - then); /* of course, you could
* use long for secs now,
* but that would make it
* more difficult to use
* difftime in the future.
*/
and the rest is identical.
--
Lars Wirzenius wirzeniu at cc.helsinki.fi
More information about the Comp.lang.c
mailing list