Example usage for org.apache.commons.net TimeTCPClient getTime

List of usage examples for org.apache.commons.net TimeTCPClient getTime

Introduction

In this page you can find the example usage for org.apache.commons.net TimeTCPClient getTime.

Prototype

public long getTime() throws IOException 

Source Link

Document

Retrieves the time from the server and returns it.

Usage

From source file:ProtocolRunner.java

private static void handleTCPTime(
    TimeTCPClient client, ProtocolRunner runner) 
    throws IOException {
        long origTime = client.getTime();
            //from   w w w  .  jav  a2s . c  o m
        // remember that the long time returned from the server is the 
        // seconds since midnight Jan 1900 and Date in Java is number of
        // seconds since midnight Jan 1970. NET TCPClient provides the time
        // in both formats but you cannot call them both one after another
        // as the internal getDate uses getTime, but the line has already
        // been closed if you have called getTime before.
        runner.getTCPServerResponse().append(
        "Time returned from server: " +  origTime + "\r\n" +
        "Converted to Date: " + 
        new Date(((origTime) - TimeTCPClient.SECONDS_1900_TO_1970)*1000L));
}