我知道我们可以使用clock_gettime(CLOCK_MONOTONIC).
我尝试问的问题是,如果我需要从纪元开始的纳秒时间,那将是一个巨大的数字。
例如:
13438461673这样13438461673 * 1000000000我如何将它放入 64 位整数中?
CLOCK_MONOTONIC是来自任意时期的,并且实际上根据机器和 Linux 中的每次启动而有所不同。您应该仅使用它来测量间隔,即
(int64_t)(after.tv_sec - before.tv_sec) * (int64_t)1000000000UL\n+ (int64_t)(after.tv_nsec - before.tv_nsec)\nRun Code Online (Sandbox Code Playgroud)\n\n。对于时间戳,请使用CLOCK_REALTIME,因为它使用 1970-01-01 00:00:00 UTC 纪元。int64_t可以处理CLOCK_REALTIME纳秒精度的时间戳 \xe2\x80\x93
(int64_t)(t.tv_sec) * (int64_t)1000000000 + (int64_t)(t.tv_nsec)\nRun Code Online (Sandbox Code Playgroud)\n\n\xe2\x80\x93,至少从 1679 年到 2261 年;范围是 \xc2\xb1292 年,而不是 \xc2\xb1145 年。
\n\n\xe2\x80\x93 名义动物
\n