【发布时间】:2019-12-18 22:00:50
【问题描述】:
我正在创建一个 python 模块,它将从选择的 NTP 池服务器输出时间到毫秒精度,作为展示服务器时间戳如何变化的练习。到目前为止,我已经能够将原始服务器时间戳打印到一秒精度内,但我怎样才能获得毫秒精度?
ntp_pool = '0.pool.ntp.org', \
'uk.pool.ntp.org', \
'ie.pool.ntp.org'
def get_ntp_time():
for item in ntp_pool:
call = ntplib.NTPClient()
response = call.request(item, version=3)
print(time.ctime(response.orig_time))
【问题讨论】:
-
回答:不要使用ntplib,因为它不能正确解析
root_delay。请参阅tools.ietf.org/html/rfc5905“NTP 短格式”,它与github.com/Tipoca/ntplib/blob/master/ntplib.py#L185 不一致。