Advertisement
Guest User

Untitled

a guest
Apr 16th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.56 KB | None | 0 0
  1. private static final String NTP_SERVER = "ntp4.stratum1.ru";
  2.  
  3.     /**
  4.      * Get atomically correct current date from stratum 1 NTP-server
  5.      *
  6.      * @return system time with computed delta between system time and NTP-server
  7.      * @throws IOException
  8.      */
  9.     public Date getAtomicallyCorrectDate() throws IOException {
  10.         NTPUDPClient client = new NTPUDPClient();
  11.         TimeInfo time = client.getTime(InetAddress.getByName(NTP_SERVER));
  12.         time.computeDetails();
  13.         return new Date(System.currentTimeMillis() + time.getOffset());
  14.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement