Mail Archives: djgpp/1999/01/04/04:08:12
From: | "Jeremy L. Buchmann" <jlbuchma AT pema DOT scs DOT unr DOT edu>
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | Re: time and milliseconds
|
Date: | 4 Jan 1999 06:48:49 GMT
|
Organization: | University & Community College System of Nevada
|
Lines: | 46
|
Message-ID: | <76po8h$mo$1@pema.scs.unr.edu>
|
References: | <76kg9d$3tl$1 AT nnrp1 DOT dejanews DOT com>
|
NNTP-Posting-Host: | empire.scs.unr.edu
|
NNTP-Posting-User: | unauthenticated_user
|
User-Agent: | tin/pre-1.4-981114 ("The Watchman") (UNIX) (OSF1/V4.0 (alpha))
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Reply-To: | djgpp AT delorie DOT com
|
leonj AT geocities DOT com wrote:
: Is there a way to retreive milliseconds from the time function?
: Is there a source clip to show this...?
The ftime() function is probably the most portable way of doing this. I
have used it in Unix and it is listed in the DJGPP libc.a reference, so I
assume it works there, too. It looks like this:
#include <sys/timeb.h>
int ftime(struct timeb *buf)
It stores the current time in the timeb structure buf.
The format of struct timeb is:
struct timeb {
time_t time; //This is your normal time() structure
unsigned short millitm //milliseconds
... //some other stuff
}
Here is how I used it in a Unix program (compiled on Solaris if it
matters):
int SystemTime::click()
{
timeb *tp = new timeb;
if (ftime(tp) == 0) //if ftime() returns okay...
{
milliseconds = tp->millitm; //extract milliseconds here
time_t *timecalptr = &tp->time;
tm* tmptr = localtime(timecalptr);
seconds = tmptr->tm_sec;
minutes = tmptr->tm_min;
}
}
Like another poster said, the "granularity" of system clocks garantees
that millisecond values won't be very accurate, but it's better than
nothing.
-------------------------------------------------------------------
Jeremy Buchmann "Those who trade freedom for safety deserve
jlbuchma AT scs DOT unr DOT edu neither freedom nor safety." -- Ben Franklin
-------------------------------------------------------------------
- Raw text -