How do I get the unix timestamp in C as an int?

后端 未结 5 495
借酒劲吻你
借酒劲吻你 2020-12-07 22:05

I would like to get the current timestamp and print it out using fprintf.

5条回答
  •  盖世英雄少女心
    2020-12-07 22:46

    An important point is to consider if you perform tasks based on difference between 2 timestamps because you will get odd behavior if you generate it with gettimeofday(), and even clock_gettime(CLOCK_REALTIME,..) at the moment where you will set the time of your system.

    To prevent such problem, use clock_gettime(CLOCK_MONOTONIC_RAW, &tms) instead.

提交回复
热议问题