1

Is there a way to access the time given from any particular atomic clock website by using a python module?

I am not looking for extreme accuracy. I am looking for a way to make sure my program gets the correct time in case the users cpu time is incorrect.

I have searched on the python 3 module index and have found time modules but none mention the atomic clock.

I have also looked on google and found a few mentions but nothing that was current and that could be useful.

Edit: Thanks for the info everyone. I guess I will just have to make sure the users clock is correct or have them make sure of it. Maybe I can just check the atomic clock when the user starts the program and then if their clock is off by a certain amount, show a pop up that lets them know of the difference in time and give them an option to disable the popup.

Thanks! Zach

zkirkland
  • 12,175
  • 3
  • 16
  • 18
  • *The* atomic clock? There's more than one, and none of them are in your computer. Which one do you want? (Also, they'll all have network lag, so if you're doing this for the precision, you'll need a new idea.) – user2357112 Jul 31 '13 at 19:42
  • Something like time.clock()? – sihrc Jul 31 '13 at 19:44
  • Yes, THE atomic clock. and its not so much for accuracy in milliseconds or even seconds but just a way for my program to get the current time without worrying if the user's cpu time is correct. – zkirkland Jul 31 '13 at 19:45
  • 2
    http://stackoverflow.com/questions/1599060/how-can-i-get-an-accurate-utc-time-with-python – Matthew Wesly Jul 31 '13 at 19:50
  • There is more than one atomic clock. For instance, the [International Atomic Time](http://en.wikipedia.org/wiki/International_Atomic_Time) standard is calculated as the weighted average of two hundred atomic clocks. Is that what you want? – Kevin Jul 31 '13 at 19:50
  • There is not "The" atomic clock. All time is based on one clock located at some naval base i think. You can't directly interface with any atomic clock (unless you have one yourself). Why do you need the precision? – Delusional Logic Jul 31 '13 at 19:52
  • Oh I see what you mean. I apologize for the lack of clarification. I don't think it matters which one. Lets go with the International Atomic Time. – zkirkland Jul 31 '13 at 19:52
  • You don't need an "atomic clock", what you most likely need is access to an NTP server. – Thomas Orozco Jul 31 '13 at 19:59
  • 1
    Why did I get a negative feedback? What about my question deserved that? – zkirkland Jul 31 '13 at 20:02

1 Answers1

7

ntplib is what i use for synchronization in python. If you really wanted accuracy you could use that. Otherwise I'd just make sure your clock is right and use

>>> from datetime import datetime
>>> datetime.now()

NTPLIB example

>>>import ntplib
>>>from time import ctime
>>>c = ntplib.NTPClient()
>>>response = c.request('europe.pool.ntp.org', version=3)
>>>ctime(response.tx_time)
'Sun May 17 09:32:48 2009'
Stephan
  • 16,509
  • 7
  • 35
  • 61