Computer clock

Asked

Viewed 80 times

2

Is it possible to calculate the difference between two time records separated by less than one second using the computer clock? For example, between 12h00m00s000ms and 12h00m00s050ms.

  • See if you can get help http://stackoverflow.com/a/16276032/221800

1 answer

1


Take a look at this: clock_getres, clock_gettime, clock_settime And here: http://man7.org/linux/man-pages/man2/clock_gettime.2.html

int clock_getres(clockid_t clk_id, struct timespec *res);

The function clock_getres() finds the resolution (accuracy) of the watch clk_id specified, and, if res is not NULL, stores the result in the struct timespec pointed by res. The resolution of clocks depends on implementation and cannot be configured by a particular process. If the time value pointed by the argument tp of clock_settime() is not a multiple of res, then it is truncated to a multiple of res.

int clock_gettime(clockid_t clk_id, struct timespec *tp);
int clock_settime(clockid_t clk_id, const struct timespec *tp);

The functions clock_gettime() and clock_settime() recover and assign the time of the clock clk_id specified.

  • 2

    The idea of rejecting answers only with a link is not only a question of the link "disappear" or not: it is important for the community to have content here, and in Portuguese. If you don’t want to translate the documentation, you are in your right (by the way, I’ll give you a little help on this... ;) ) but could at least put an example of usage, an informal explanation of what the methods do, or something like that.

  • P.S. I’m sorry if you think it wasn’t right for me to edit your answer without your consent. Anything, just revert to original review.

  • The problem is that you translated a "piece" of documentation. I am Frances and we have in many cases the same problem with documentation mainly in English. It is possible to translate, right. But in this case, I think that Francis should not only keep the translation but that he should read the full doc. Good luck to him! And thank you so much for Grandpa!

  • 1

    Of course, a link accompanying the answer is always welcome, even if in another language. The problem is when the whole or almost the whole of the answer consists of the link.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.