我需要从 NTP 服务器获取英国时间。在网上找到了一些东西,但是每当我尝试代码时,我总是会得到一个返回日期时间,和我的电脑一样。我更改了计算机上的时间以确认这一点,我总是得到它,所以它不是来自 NTP 服务器。
import ntplib
from time import ctime
c = ntplib.NTPClient()
response = c.request('uk.pool.ntp.org', version=3)
response.offset
print (ctime(response.tx_time))
print (ntplib.ref_id_to_text(response.ref_id))
x = ntplib.NTPClient()
print ((x.request('ch.pool.ntp.org').tx_time))
原文由 RobouteGuiliman 发布,翻译遵循 CC BY-SA 4.0 许可协议
这将起作用(Python 3):