code: public static long syncCurrentTime() throws Exception {
          // The time protocol sets the epoch at 1900,
          // the java Date class at 1970. This number
          // converts between them.
          long differenceBetweenEpochs = 2208988800L;
  
          // If you'd rather not use the magic number uncomment
          // the following section which calculates it directly.
  
          /*
           * TimeZone gmt = TimeZone.getTimeZone("GMT"); Calendar epoch1900 =
           * Calendar.getInstance(gmt); epoch1900.set(1900, 01, 01, 00, 00, 00);
           * long epoch1900ms = epoch1900.getTime().getTime(); Calendar epoch1970
           * = Calendar.getInstance(gmt); epoch1970.set(1970, 01, 01, 00, 00, 00);
           * long epoch1970ms = epoch1970.getTime().getTime();
           *
           * long differenceInMS = epoch1970ms - epoch1900ms; long
           * differenceBetweenEpochs = differenceInMS/1000;
           */
  
          InputStream raw = null;
          Socket theSocket = null;
          try {
              theSocket = new Socket(DEFAULT_HOST, DEFAULT_PORT);
              raw = theSocket.getInputStream();
  
              long secondsSince1900 = 0;
              for (int i = 0; i < 4; i++) {
                  secondsSince1900 = (secondsSince1900 << 8) | raw.read();
              }
  
              long secondsSince1970 = secondsSince1900 - differenceBetweenEpochs;
              return secondsSince1970 * 1000;
          } finally {
              if (raw != null) raw.close();
              if (theSocket != null) theSocket.close();
          }
      }
docs: NTP服务器地址