import java.net.*;
import java.io.*;

public class DateAtHost extends java.util.Date {
  static int timePort = 37;
  static final long offset = 2208988800L;   //  Seconds from century to 
                                            //   Jan 1, 1970 00:00 GMT

  public DateAtHost( String host ) throws IOException {
   this( host, timePort );
  }

  public DateAtHost( String host, int port ) throws IOException {

    Socket sock = new Socket( host, port );
    DataInputStream din = new DataInputStream(sock.getInputStream() );
    int time = din.readInt();
    sock.close();
    setTime( (((1L << 32) + time) - offset) * 1000 ) ;
  }

  // Example usage: java DateAtHost time.nist.gov 
  public static void main (String [] args) {
    try {
      System.out.println( new DateAtHost( args[0] ) );
    } catch (UnknownHostException e){
      System.out.println("Host " + args[0] +" is unknown."); 
    } catch (IOException e){
      System.out.println("IO Exception"); 
    }
  }
}



