Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. import os, ntplib
  2. from time import ctime
  3. from time import strptime
  4.  
  5. def online_date():
  6. global day
  7. global month
  8. global year
  9. ntp_client = ntplib.NTPClient()
  10. res = ntp_client.request('pool.ntp.org')
  11. result = ctime(res.tx_time)
  12. m = result.split()
  13. month_word = m[1]
  14. year = m[4]
  15. day = m[2]
  16. month_num = strptime(month_word, '%b').tm_mon
  17. month = str(month_num)
  18.  
  19.  
  20. online_date()
  21. command = month + '-' + day + '-' + year
  22. print('current date (mm-dd-yyyy): ' + command)
  23. os.system('date ' + command)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement