Python gets and prints the current time from the network time server and an experience with PIP installation Ntplib

Source: Internet
Author: User

First you need to install Ntplib, section one through PIP installation.

Ubuntu next section one installs the PIP via the following instructions:

$ sudo apt-get install Python-pip

Install ntplib using the following instructions:

$ sudo pip install Ntplib

Find Pip is really a good thing, before downloading an outside Python library is very troublesome, now with the PIP on the line, feel more convenient than the Java maven.

The following code relies on Ntplib to request the current time and print to an NTP server through the network Time protocol, or NTP.

Code:

#/usr/bin/env pythonImportNtplib fromTimeImportCTimedefprint_time (): Ntp_client=Ntplib. NTPClient () Response= Ntp_client.request ('pool.ntp.org')    PrintCTime (response.tx_time)if __name__=='__main__': Print_time ()
View Code

Python gets and prints the current time from the network time server and an experience with PIP installation Ntplib

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.