Solved

time_t / difftime in millisconds

Posted on 1997-09-16
6
4,040 Views
Last Modified: 2006-11-17
Does anyone have a function in ANSI C that breaks down the time_t and difftime functions into milliseconds instead of seconds? I am running it on a dos platform based machine.
0
Comment
Question by:kph1
6 Comments
 
LVL 3

Expert Comment

by:rmichels
ID: 1254706
time_t cannot be broken down into milliseconds.  It is a integer count of seconds, and does not have a resolution smaller than seconds.  What operating system are you using?
0
 

Author Comment

by:kph1
ID: 1254707
Edited text of question
0
 
LVL 4

Accepted Solution

by:
jos010697 earned 50 total points
ID: 1254708
rmichels is right. All you can do (I'm talking portability here)
is to give the clock(void) function a try. This function
returns a clock_t value. The <time.h> file defines a manifest
constant CLOCKS_PER_SEC, i.e. every other second, clock()
returns a new value CLOCKS_PER_SEC units higher than the
previous one ...

kind regards,

Jos aka jos@and.nl
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 3

Expert Comment

by:rmichels
ID: 1254709
If you were under WIn95 or WinNT you could use timeGetTime (part of the multimedia API) which is down to milliseconds.

I think functions that do better than that are dependant on the hardware etc.
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1254710
Also have a look at the C FAQ questions:

19.37:  How can I implement a delay, or time a user's response, with sub-second resolution?
0
 

Expert Comment

by:jolusg
ID: 7360984
You can use the function ftime.

#include <sys/time.h>

int ftime(
          struct timeb *tp );

The struct timeb contains a field millitm with the milliseconds.

jolusg
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now