How to find time difference between two computers?

I'm running a distributed computer setup with one machine as time server for the other so the two are in sync to the accuracy of a few ms.

I followed answers on this question: How do I setup a local NTP server?

I was able to setup successfully, but I want to know if there is a way to query ntp or any other program and know the time difference between the two machines?


The command ntpq -np will output information about time difference between your NTP server and the sources it is synchronizing to (I'm not sure if this is exactly what you want). If you omit -n parametr (ie. ntpq -p) it will display hostnames instead of IP addresses (slightly slower, as it has to do DNS lookups).

The command ntpdate -q <address> will output information about time difference between your machine and the time source specified in <address>. The -q parametr is important, as without it ntpdate will try to sync time to the specified machine instead of just outputting the difference. It is possible that you need to type full path to ntpdate (eg. /usr/sbin/ntpdate) if running from non-root user.

(ntpq should be installed with ntp package, ntpdate is a separate package so you have to install it if it's not already installed)