How to check time from internet using bash or python? -
this question has answer here:
- ntp client in python 5 answers
- python getting date online? 5 answers
this should simple task, after 2 hours of searching , reading documents failed find way check date , time internet using bash or python without installing ntplib.
i looking equivalent of pythons now() or bash $ date, using ntp (or other way) correct date , time internet. methods find (such ntpd) meant correct system time, not purpose.
easy way correct time in python
import time import os try: import ntplib client = ntplib.ntpclient() response = client.request('pool.ntp.org') os.system('date ' + time.strftime('%m%d%h%m%y.%s',time.localtime(response.tx_time))) except: print('could not sync time server.') print('done.')
Comments
Post a Comment