ntp client in python

后端 未结 5 1311
攒了一身酷
攒了一身酷 2020-12-03 11:16

I\'ve written a ntp client in python to query a time server and display the time and the program executes but does not give me any results. I\'m using python\'s 2.7.3 integ

5条回答
  •  臣服心动
    2020-12-03 11:38

    Use ntplib:

    The following should work on both Python 2 and 3:

    import ntplib
    from time import ctime
    c = ntplib.NTPClient()
    response = c.request('pool.ntp.org')
    print(ctime(response.tx_time))
    

    Output:

    Fri Jul 28 01:30:53 2017
    

提交回复
热议问题