i need a real time clock in ansi c which provide an accuracy upto miliseconds?
i am working on windows a windows base lib is also acceptable thanx in advance.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can’t do it with portable code prior to C11.
Starting with C11, you can use
timespec_get, which will often (but doesn’t necessarily) provide a resolution of milliseconds or better. Starting from C23, you can calltimespec_getresto find out the resolution provided.Since you’re using Windows, you need to start out aware that Windows isn’t a real-time system, so nothing you do is really guaranteed to be accurate. That said, you can start with
timeBeginPeriod(1);to set the multimedia timer resolution to 1 millisecond. You can then calltimeGetTime()to retrieve the current time with 1 ms resolution. When you’re done doing timing, you calltimeEndPeriod(1)to set the timer resolution back to the default.