Microsecond time

From Tom's notes
Revision as of 13:05, 27 March 2018 by Tom (talk | contribs) (Created page with "I needed this one on Solaris to display microseconds (µseconds): time_ms.c <source lang="c"> #include <sys/time.h> main() { struct timeval tv; gettimeofday(&tv, (voi...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

I needed this one on Solaris to display microseconds (µseconds):

time_ms.c

#include <sys/time.h>
main()
{
    struct timeval tv;
    gettimeofday(&tv, (void*)0);
    // Print time with milliseconds and decimal separator
    // printf("%d.%03d\n", tv.tv_sec, tv.tv_usec/1000);
    // Print time with microseconds without decimal separator
    printf("%d%06d\n", tv.tv_sec, tv.tv_usec);
}

Compile:

gcc time_ms.c -o time_ms

Credits: https://superuser.com/questions/178330/milliseconds-from-solaris-command-line