Reputation: 179
How can I get the correct UTM time regardless of whether the user has set their Windows OS date and time correctly?
I have done some tests where I set my Windows clock to a different time and run the exact same code. Each time it outputs the Windows clock time. I am looking for code to always output the correct UTM time.
Code:
from datetime import datetime
from time import time
print time()
print datetime.utcnow()
Upvotes: 0
Views: 204
Reputation: 2990
You'd want to use NTP module: https://pypi.python.org/pypi/ntplib/
Example from the site:
import ntplib
from time import ctime
c = ntplib.NTPClient()
response = c.request('europe.pool.ntp.org', version=3)
ctime(response.tx_time)
Upvotes: 3