import ntptime,time
#本地话时间 东八区
def datetime():
date=time.localtime(time.time()+28800)
#(2024, 4, 29, 9, 58, 14, 0, 120) 年 月 日 时 分 秒 周 全年的第几天
return date
# 定义NTP服务器列表
ntp_servers = [
'ntp.ntsc.ac.cn',
'ntp1.aliyun.com',
'ntp.tencent.com',
'pool.ntp.org'
]
#NTP同步
def ntp(ntp_servers):
for server in ntp_servers:
try:
# 尝试从当前服务器同步时间
ntptime.host = server
ntptime.settime()
print("时间已从 {} 同步".format(server))
return
except Exception as e:
print("从 {} 同步时间失败: {}".format(server, e))
continue
print("无法从任何服务器同步时间")
ntp(ntp_servers)
-
近期文章
近期评论
- admin 发表在《PDF文件分割图片》
- admin 发表在《混乱的五月即将告以段路》
- admin 发表在《系规看来不是300页那么简单》
- admin 发表在《系规看来不是300页那么简单》
- admin 发表在《扩展计划UserScript》
归档
- 2026 年 2 月
- 2026 年 1 月
- 2025 年 12 月
- 2025 年 11 月
- 2025 年 10 月
- 2025 年 9 月
- 2025 年 8 月
- 2025 年 7 月
- 2025 年 6 月
- 2025 年 5 月
- 2025 年 4 月
- 2025 年 3 月
- 2025 年 2 月
- 2025 年 1 月
- 2024 年 12 月
- 2024 年 11 月
- 2024 年 10 月
- 2024 年 9 月
- 2024 年 8 月
- 2024 年 7 月
- 2024 年 6 月
- 2024 年 5 月
- 2024 年 4 月
- 2024 年 2 月
- 2024 年 1 月
- 2023 年 12 月
- 2023 年 11 月
- 2023 年 10 月
- 2022 年 10 月
- 2022 年 9 月
- 2022 年 8 月
- 2022 年 7 月
- 2022 年 6 月
- 2022 年 5 月
- 2022 年 4 月
- 2022 年 3 月
- 2022 年 1 月
- 2021 年 11 月
- 2021 年 10 月
- 2021 年 9 月
- 2021 年 4 月
- 2020 年 11 月
- 2020 年 10 月
- 2020 年 8 月
- 2020 年 5 月
- 2020 年 4 月
- 2020 年 1 月
- 2019 年 11 月
- 2019 年 7 月
- 2019 年 2 月
- 2019 年 1 月
- 2018 年 12 月
- 2018 年 11 月
- 2018 年 8 月
分类
友情链接
其他操作