Created
March 13, 2025 10:41
-
-
Save ArthurDelannoyazerty/8f6422f9145bb559f9f509cc6426fa08 to your computer and use it in GitHub Desktop.
Python script that get the UTC time from a NTP server. Usefull when the machine clock is wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import ntplib | |
import logging | |
logger = logging.getLogger(__name__) | |
def get_current_utc_time() -> float: | |
logger.debug('Requesting current UTC time') | |
response = ntplib.NTPClient().request('pool.ntp.org') | |
logger.debug(f'UTC time : {response.tx_time} | {time.strftime('%Y-%m-%dT%H-%M-%S',time.gmtime(response.tx_time))}') | |
return response.tx_time |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment