Time Info

Christopher Neufeld neufeld at aurora.physics.utoronto.ca
Mon May 27 02:16:43 AEST 1991


In article <268 at bria.UUCP> uunet!bria!mike writes:
>In an article, 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.
>
>#include <time.h>
>#include <sys/types.h>
>
>time_t
>deltat(since)
>time_t since;
>{
>time_t now;
>
>	time(&now);
>	return(now - since);
>}
>
   I would rather return the value:  difftime(now, since) / 60.0
On my compiler, 'now-since' doesn't mean minutes or seconds, or
anything else obvious.
   You can also write the function as:
return(difftime(time(NULL),since)/60.0);

which is now so short that it might as well be a #define macro.

#define DELTAT(tnought) (difftime(time(NULL),tnought)/60.0)


>Michael Stefanik
>UUCP: ...!uunet!bria!mike


-- 
 Christopher Neufeld....Just a graduate student  | There no place like $FC58
 neufeld at aurora.physics.utoronto.ca    Ad astra! | They're $FF69-ing my
 cneufeld@{pnet91,pro-cco}.cts.com               | every word! Send for a
 "Don't edit reality for the sake of simplicity" | free $A56E.



More information about the Comp.lang.c mailing list