code: private static String getDaytimeReply(
          String address,
          int port,
          int timeout
      ) throws IOException {
  
          IOException ioe = null;
          Socket socket = null;
          StringBuilder sb = null;
  
          try {
  
              socket = new Socket(address, port);
              socket.setSoTimeout(timeout * 1000);
  
              InputStream is = socket.getInputStream();
              InputStreamReader ir = new InputStreamReader(is);
              BufferedReader br = new BufferedReader(ir);
  
              int len;
              char[] chars = new char[100];
              sb = new StringBuilder();
  
              while ((len = br.read(chars)) != -1) {
                  sb.append(chars, 0, len);
              }
  
              is.close();
              ir.close();
              br.close();
  
          } catch (IOException ex) {
  
              ioe = ex;
  
          } finally {
  
              try {
                  if (socket != null) {
                      socket.close();
                  }
              } catch (IOException ex) {
                  System.err.println(
                      "Ignored exception while closing time server socket: "
                      + ex.getMessage()
                  );
                  ex.printStackTrace(System.err);
              }
  
          }
  
          if (ioe == null) {
              return sb.toString();
          } else {
              throw ioe;
          }
  
      }
docs: Original-Antwort eines älteren Uhrzeit-Servers holen (RFC 867)