net.i2p.time
Class NtpClient

java.lang.Object
  extended by net.i2p.time.NtpClient

public class NtpClient
extends java.lang.Object

NtpClient - an NTP client for Java. This program connects to an NTP server and prints the response to the console. The local clock offset calculation is implemented according to the SNTP algorithm specified in RFC 2030. Note that on windows platforms, the curent time-of-day timestamp is limited to an resolution of 10ms and adversely affects the accuracy of the results.

Author:
Adam Buckley (minor refactoring by jrandom)

Constructor Summary
NtpClient()
           
 
Method Summary
static long currentTime(java.lang.String serverName)
          Query the given NTP server, returning the current internet time
static long currentTime(java.lang.String[] serverNames)
          Query the ntp servers, returning the current time from first one we find
static long[] currentTimeAndStratum(java.lang.String[] serverNames)
          Query the ntp servers, returning the current time from first one we find Hack to return time and stratum
static void main(java.lang.String[] args)
           
(package private) static void printUsage()
          Prints usage
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NtpClient

public NtpClient()
Method Detail

currentTime

public static long currentTime(java.lang.String[] serverNames)
Query the ntp servers, returning the current time from first one we find

Returns:
milliseconds since january 1, 1970 (UTC)
Throws:
java.lang.IllegalArgumentException - if none of the servers are reachable

currentTimeAndStratum

public static long[] currentTimeAndStratum(java.lang.String[] serverNames)
Query the ntp servers, returning the current time from first one we find Hack to return time and stratum

Returns:
time in rv[0] and stratum in rv[1]
Throws:
java.lang.IllegalArgumentException - if none of the servers are reachable
Since:
0.7.12

currentTime

public static long currentTime(java.lang.String serverName)
Query the given NTP server, returning the current internet time

Returns:
milliseconds since january 1, 1970 (UTC), or -1 on error

main

public static void main(java.lang.String[] args)
                 throws java.io.IOException
Throws:
java.io.IOException

printUsage

static void printUsage()
Prints usage