net.i2p.router.time

## Class NtpClient

- java.lang.Object
- - net.i2p.router.time.NtpClient

-     public class NtpClient
      extends 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. Public only for main(), not a public API, not for external use. 2036-compliant as of 0.9.50, see NtpMessage.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `(package private) static double` | `SECONDS_1900_TO_EPOCH` difference between the unix epoch and jan 1 1900 (NTP uses that)

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `NtpClient()`

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `(package private) static long[]` | `currentTimeAndStratum(String[] serverNames, int perServerTimeout, boolean preferIPv6, Log log)` Query the ntp servers, returning the current time from first one we find Hack to return time and stratum
    `static void` | `main(String[] args)` Main entry point for the NtpClient program.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### SECONDS_1900_TO_EPOCH

          static final double SECONDS_1900_TO_EPOCH

      difference between the unix epoch and jan 1 1900 (NTP uses that)
      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### NtpClient

          public NtpClient()

  - ### Method Detail

    - #### currentTimeAndStratum

          static long[] currentTimeAndStratum(String[] serverNames,
                                              int perServerTimeout,
                                              boolean preferIPv6,
                                              Log log)

      Query the ntp servers, returning the current time from first one we find Hack to return time and stratum
      Parameters:
        `log` - may be null
      Returns:
        time in rv[0] and stratum in rv[1]
      Throws:
        `IllegalArgumentException` - if none of the servers are reachable

    - #### main

          public static void main(String[] args)
                           throws IOException

      Main entry point for the NtpClient program. Usage: java -jar i2p/lib/router.jar NtpClient [-6] [servers...] The optional "-6" flag forces IPv6 DNS lookups. If no servers are specified, the default "pool.ntp.org" is used. This program queries the specified NTP servers and prints the current time along with stratum and offset information.
      Parameters:
        `args` - command-line arguments; optionally "-6" followed by list of NTP servers
      Throws:
        `IOException` - if a network error occurs