How can I print current microseconds time in C on Unix platform?
1900-01-01-00.00. 00.000000. Last 6 digits are micro seconds.
Time#usec() is a Time class method which returns the number of microseconds for time.
A microsecond is a unit of time in the International System of Units (SI) equal to one millionth (0.000001 or 10−6 or 1⁄1,000,000) of a second. Its symbol is μs, sometimes simplified to us when Unicode is not available.
A microsecond is equal to one millionth (10−6 or 1/1,000,000) of a second. One microsecond is to one second as one second is to 11.54 days. To keep our blinking example alive: 350,000 microseconds. Still too slow.
In Linux and BSDs, you can use the gettimeofday()
function. This populates a timeval
struct which has a field for seconds since the epoch and a field for microseconds. This function is deprecated. The higher resolution clock_gettime() is the favored replacement, however Mac OS X does not implement it. I'm not sure if Windows implements either of these.
There is no portable (multiplatform) way to get that number. On Linux (or other POSIX systems) for example there is the call gettimeofday that provides exactly that precision (accuracy however will depend if that timing is available and implemented on the specific hardware).
The C standard doesn't provide a standard means for that. However the clock()
function returns time in CLOCK's. there are CLOCKS_PER_SEC
CLOCK's in a second. On my machine and implementation, CLOCKS_PER_SEC is defined as 1000. Both clock
and CLOCKS_PER_SEC
are defined in <time.h>
. Hope this helped
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With