在python中获取正确时间的简单方法 [英] Easy way to get the correct time in python

查看:74
本文介绍了在python中获取正确时间的简单方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个群集上运行一些作业,每个节点上的日期都略有不同。是否有一种简单的方法可以通过python从互联网上的某个地方获取时间,或者我需要让sysadmin更频繁地同步计算机之间的时间?

I'm running some jobs on a cluster where the dates on each node are slightly off from one another. Is there an easy way to get the time from somewhere on the internet via python or do I need to have the sysadmin sync the times between the machines more frequently?

d想在我启动的每个作业的输出中添加时间戳,但是显然python time.strftime()等的准确性将取决于计算机知道正确的时间。我希望在几秒钟之内就能获得准确性,但现在在几分钟之内即可。

I'd like to put a time-stamp in the output from each job I launch, but obviously the accuracy of the python's time.strftime() etc are going to depend on the machine knowing the correct time. I'd love accuracy within a few seconds, but right now it's within minutes.

推荐答案

尝试使用ntplib for python。我已经试了一下,它似乎很稳定。

Try ntplib for python. I've played around with it a bit and it seems pretty stable.

https://pypi.python.org/pypi/ntplib/

这篇关于在python中获取正确时间的简单方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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