Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use http time synchronization to set system time source code by Python

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article introduces Python how to use http time synchronization to set up the system time source code, the content is very detailed, interested friends can refer to, hope to be helpful to you.

Python mode uses http time synchronization to set the system time source code, the system environment is ubuntu 12.04, Python2.7 version. The time, os, and httplib methods are required.

Python uses http time synchronization to set the system time. The source codes are as follows:

`#-*-coding:utf8-*-``import``time`import``os`def``get_webservertime (host): ``conn`` = ``client.HTTPConnection (host) ``conn.request (```client.HTTPConnection (host) ``r`` = `conn.getresponse () ``ts`` = ```getresponse () ``ts`` = ```date' ``) `# get the http header date ````# convert GMT time to Beijing time ``time`` = ``time.mktime (time.strptime (ts``5``) ``"d% b% Y% H:%M:%S GMT"``) ``+`` (``8`` * ``60`` * `60``) ``ltime`` = ``time.gmtime (local_time) ``# use date to set the time ``dat`` = ```date-u-s "% d-%d-%d% d:%d:%d" ``%`` (ltime.tm_year,ltime.tm_mon,ltime.tm_mday,ltime.tm_hour,ltime.tm_min) Ltime.tm_sec) ``os.system (dat) ``get_webservertime (``www.baidu.com' ``) `about how Python uses http time synchronization to set up the system time source code here. I hope the above content can be of some help to you and learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report