首页 > 其他 > 详细

时间同步工具

时间:2015-07-09 09:34:47      阅读:228      评论:0      收藏:0      [点我收藏+]
如果你的电脑时间老是不对,可以用下面的脚本,放任务管理器里面运行。
import os
import time
import ntplib
def SyncTime(ntpserv):
try:
c = ntplib.NTPClient()
print ‘Synctime from %s ‘ % ntpserv
response = c.request(ntpserv)
ts = response.tx_time
except ntplib.NTPException,e:
print ‘Synctime Failed,‘,e
return False
else:
_date = time.strftime(‘%Y-%m-%d‘,time.localtime(ts))
_time = time.strftime(‘%X‘,time.localtime(ts))
os.system(‘date {} && time {}‘.format(_date,_time))
print ‘Synctime Success!‘
return True

if __name__ == ‘__main__‘:
with open(‘ntpserv.ini‘) as f:
for eachline in f:
ntpserv = eachline.strip(‘\n\r‘)
if SyncTime(ntpserv):
break

时间同步工具

原文:http://www.cnblogs.com/xiewb/p/4632133.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!