On Apr 13, 2005, at 3:12 PM, John C. Randolph wrote: On Apr 13, 2005, at 11:57 AM, M. Carlson wrote:
[NSDate date] returns only the current system time. I would like to access an NTP server such as time.apple.com to obtain the current time. What is the Cocoa way to do this?
Ordinarily, you'd have the system prefs set to synchronize with an NTP server. If you want to do it manually, you can look up the RFC's for the NTP protocol, and use NSStream to talk to the host of your choice.
If you've got ntpq installed on your machine, you could probably fire off an NSTask and get the time that way.
% ntpq -c "readvar 0 clock" status=c011 sync_alarm, sync_unspec, 1 event, event_restart, clock=c61034ee.ad30ad46 Tue, Apr 19 2005 18:54:54.676
Although, like John said, depending on the precision of your requirements, you might get the source from http://www.ntp.org/ and pull out what you need.
Dan
|