- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在创建一个 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))
最佳答案
for 循环可能会为您的结果着色,因为每次迭代都会有时间流逝。
在任何情况下,ntp 响应都是微秒级精度的时间戳,因此限制似乎在 time.ctime
之内。 ,这只会下降到第二个精度
你可以使用 datetime.fromtimestamp
相反,还可以选择 strftime
使其更漂亮。我的示例半心半意地模仿了您现有代码的输出。
from datetime import datetime
def get_ntp_time():
for item in ntp_pool:
call = ntplib.NTPClient()
response = call.request(item, version=3)
t = datetime.fromtimestamp(response.orig_time)
print(t.strftime("%a %b %d %H:%M:%S.%f"))
关于python - 如何使用 Python ntplib 将 ntp 服务器时间精确到毫秒?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31255633/
我可以使用 ntpq 查询本地 NTP 守护程序以获取系统变量。例如: $ ntpq -c rv associd=0 status=0615 leap_none, sync_ntp,
SNTP 是对完整 NTP 规范的简化。 我想对集成在 Windows XP 中的内部 SNTP 服务器使用完整的 NTP 客户端。这会起作用还是 NTP 客户端需要一个完整的 NTP 服务器才能工作
在 NTP rfc 中定义 “NTP 算法的目标是最小化 UTC 和系统时钟之间的时间差和频率差。” 我能理解“时差”,但 NTP 尝试同步的“频差”是什么? 最佳答案 频率差异是您的时钟与 NTP
我有一 block 带有 I/O 引脚的主板,并且我编写了一个 C 库,其中包含设置和查询这些 I/O 引脚状态的函数。假设这些函数之一的名称是 get_pin(int pin_no) ,并返回该引脚
通过运行命令使用 ntp 同步时出现错误sudo ntpd -gq . 28 Sep 05:19:30 ntpd[1919]: receive: KoD packet from 172.19.79.1
我尝试阅读 NTPv4 RFC 4905。我似乎无法理解它计算下一个轮询间隔以向其对等方发送 NTP 请求数据包的依据是什么。 ppoll 和 hpoll 在查找轮询时间中的作用是什么?另外,MINP
我正在阅读 NTPv4 rfc 以更好地理解 ntp 使用的机制。所以,到目前为止,基本的想法似乎很简单。但我对如何 NTP Clock Discipline works 有点困惑. 在 NTPv4
我试图弄清楚我需要在 NTP 请求包中发送(客户端)什么以从服务器检索 NTP 包。我正在使用 Cortex M3 上的 LWIP,Stellaris LM3S6965 我知道我将收到一个 UDP h
NTP 如何计算往返延迟时间和偏移量。 最佳答案 要将其时钟与远程服务器同步,NTP 客户端必须计算往返延迟时间和偏移量。往返延迟计算为 delta = (t_3 - t_0) - (t_2- t_1
我想知道 NTP 是否可用于测量分布式计算环境中发布者和订阅者之间的延迟。所有节点上都配置了 NTP。我能够单独收集统计数据。如何使用 NTP 准确测量发布者和服务端之间的延迟 最佳答案 您可以使用
我写了一个非常小的ntp客户端,但是发送数据包后我没有收到服务器的响应,我已经用tcpdump确认了这一点。 我定义了一个结构体,用于传输ntp数据包。 struct NtpMessage_t {
我正在尝试转换 RFC 5905 NTP Short Format到秒。 NTP 短格式是 uint32_t,前 16 位是秒(即秒 = format >> 16),其他 16 位是秒的小数部分(即小
我有一个服务器/客户端应用程序,我需要将客户端的时间与服务器的时间同步。因此,我需要在服务器应用程序上实现一个 NTP 服务器(或类似的),并在客户端实现一个 NTP 客户端。 NTP 不是必需的,但
我需要实现自己的 NTP 服务器,或者只选择一个现有的服务器并将其集成到一个应用程序中。我试图在 C++ 中找到可用的 NTP 服务器源代码,但我没有成功。谁能帮帮我? 最诚挚的问候, 最佳答案 我不
我正在使用 iOS-ntp framework而且我有一种我无法理解的奇怪行为。目前是 13:14,但我在进行对开通话时将设备上的时间更改为 13:34: NSDate *deviceDate = [
问题摘要 打开 NTP - 版本 4.2.6p3 - 时钟未同步到低层服务器。 问题描述 我正在 Ubuntu 系统中运行 NTP 单播客户端。 我有 3 台服务器,Server1-Stratum=1
在本地网络中,我有一个本地 NTP 服务器,它使用层 2 来同步其时间。 本地网络内有很多客户端只能看到本地 NTP 服务器。客户端持续同步到本地 NTP 服务器。 由于一些具体情况,我希望避免本地
我正在尝试在无法访问互联网的本地网络中配置 NTP 服务器(即使错误,我也需要所有计算机具有相同的时间)。 我已经为客户端和服务器配置了/etc/ntp.conf 文件。在系统启动时,我运行 ntpd
我使用 NTP 协议(protocol)已有一段时间了。最近,我遇到了一个奇怪的问题。即,当我尝试打印服务器已知的对等点列表时,大约需要 20 秒。早些时候它花费的时间更少。 [root@centos
我使用的是 ARM 嵌入式设备,但我认为这是一个常见的 Linux 问题。 我正在使用带有"file"选项的 Linux 看门狗守护程序来定期检查我的应用程序每 xx 秒左右更改一次的时间。这工作正常
我是一名优秀的程序员,十分优秀!