Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我希望编写一个 C 程序来获取系统时间,因此使用这个时间来打印出它的 ntp 等价物。
我是否正确地说以下对于 ntp 时间的秒部分是正确的?
long int ntp.seconds = time(NULL) + 2208988800;
我如何计算分数部分?
要添加的小数部分显然是 0ps ... ;-)
因此,分数的问题可以简化为系统时钟的准确度。
gettimeofday()让您获得微秒。clock_gettime() 可以让你纳秒。
gettimeofday()
clock_gettime()
无论如何,我怀疑你会达到理论上可能的分辨率,即分数允许的 32 位宽值(至少在标准 PC 上)。