package net;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;
import java.net.UnknownHostException;

public class SimpleClock {
  private static BufferedReader getTimeReader()
      throws UnknownHostException,
      IOException {
    Socket s = new Socket(
        "time-A.timefreq.bldrdoc.gov", 13);
    return new BufferedReader(
        new InputStreamReader(
            s.getInputStream()));
  }

  /**
   *  return a string representing the time from NIST
   *  output looks like:
   * 52520 02-09-03 11:06:08 50 0 0 537.5 UTC(NIST) *
   */
  public static String getTime() {
    String time = "";
    try {
      BufferedReader in = getTimeReader();
      String s = null;
      while ((s = in.readLine()) != null)
        time = time + s;
    } catch (IOException e) {
    }
    return time;
  }

  public static void main(String[] args) {
    System.out.println(SimpleClock.getTime());
  }
}