是否有将struct timeval转换为struct timespec的标准方法? [英] Is there a standard way to convert a struct timeval into a struct timespec?
问题描述
struct timeval
即时表示具有两个成员,分别为tv_sec
(秒)和tv_usec
(微秒).在此表示形式中,tv_usec
本身并不是绝对时间,它是距tv_sec
不到一秒的偏移量.
struct timeval
represents and instant in time with two members, tv_sec
(seconds) and tv_usec
(microseconds). In this representation, tv_usec
is not by itself an absolute time it is a sub second offset off of tv_sec
.
struct timespec
的工作方式相同,除了偏移量(tv_nsec
)以微秒为单位存储而不是微秒.
struct timespec
works the same way except that instead of microseconds it's offset (tv_nsec
) is stored in nanosecond units.
问题是:在这两者之间有转换的标准方法吗?
The question is: Is there a standard way to convert between these two?
推荐答案
Looking at this doc, I would think multiplying tv_usec
by 1000 is sufficient to get tv_nsec
.
更重要的是,我怀疑是不同结构的来源:它们可能由不同的时钟填充.
More important, I suspect is the source of the different structures: they could be filled by different clocks.
这篇关于是否有将struct timeval转换为struct timespec的标准方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!