Python时间同步
时间: 2023-11-05 10:21:28 浏览: 155
python同步时间脚本
Python可以使用http时间同步来设置系统时间。下面是一个示例代码:
```python
import httplib as client
import time
import os
def get_webservertime(host):
conn = client.HTTPConnection(host)
conn.request("GET", "/")
r = conn.getresponse()
ts = r.getheader('date') # 获取http头date部分
local_time = time.mktime(time.strptime(ts<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* [【Python】Python 使用http时间同步设置系统时间源码](https://blog.csdn.net/ajian6/article/details/94558385)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *3* [通过python实现同步修改本地电脑时间](https://blog.csdn.net/z564359805/article/details/127745418)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文