是否有将struct timeval转换为struct timespec的标准方法? [英] Is there a standard way to convert a struct timeval into a struct timespec?

查看:315
本文介绍了是否有将struct timeval转换为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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆