Skip to content

Instantly share code, notes, and snippets.

@manesec
Created May 4, 2024 07:58
Show Gist options
  • Save manesec/8a9a6e0ab5231536e24192c80075d725 to your computer and use it in GitHub Desktop.
Save manesec/8a9a6e0ab5231536e24192c80075d725 to your computer and use it in GitHub Desktop.
Update time from NTP SERVER with windows
import time
import os
import ntplib
client = ntplib.NTPClient()
response = client.request('ntp4.aliyun.com')
timestamp = int(response.tx_time)
date_string = time.strftime('%d-%m-%Y', time.localtime(timestamp))
print(date_string)
os.system('date ' + date_string)
time_string = time.strftime('%H:%M:%S', time.localtime(timestamp))
print(time_string)
os.system('time ' + time_string)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment