Advertisement
cd62131

clock_gettime() sample

Dec 28th, 2018
855
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.39 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <time.h>
  3. int main(void) {
  4.   struct timespec ts;
  5.   struct tm tm;
  6.   clock_gettime(CLOCK_REALTIME, &ts);
  7.   localtime_r(&ts.tv_sec, &tm);
  8.   printf("tv_sec=%ld, tv_nsec=%ld\n", ts.tv_sec, ts.tv_nsec);
  9.   printf("%d-%02d-%02dT%02d:%02d:%02d.%09ld\n", tm.tm_year + 1900,
  10.          tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec,
  11.          ts.tv_nsec);
  12. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement