Example usage for org.apache.commons.net.time TimeUDPClient SECONDS_1900_TO_1970

List of usage examples for org.apache.commons.net.time TimeUDPClient SECONDS_1900_TO_1970

Introduction

In this page you can find the example usage for org.apache.commons.net.time TimeUDPClient SECONDS_1900_TO_1970.

Prototype

long SECONDS_1900_TO_1970

To view the source code for org.apache.commons.net.time TimeUDPClient SECONDS_1900_TO_1970.

Click Source Link

Document

The number of seconds between 00:00 1 January 1900 and 00:00 1 January 1970.

Usage

From source file:it.greenvulcano.util.remotefs.RemoteManager.java

/**
 * Return current time on the remote FTP server.
 * //  w w  w.  ja  v  a 2  s.c o  m
 * @return the current time on the remote FTP server.
 */
public long getRemoteTime() {
    boolean useLocalTime = true;
    long time = -1;
    try {
        if (timeUdpClient == null) {
            timeUdpClient = new TimeUDPClient();
        }
        timeUdpClient.setDefaultTimeout(1000);
        timeUdpClient.open();
        time = (timeUdpClient.getTime(InetAddress.getByName(hostname)) - TimeUDPClient.SECONDS_1900_TO_1970)
                * 1000;
        timeUdpClient.close();
        useLocalTime = false;
    } catch (Exception exc) {
        logger.warn("Could not detect server time: " + exc);
        time = System.currentTimeMillis();
    } finally {
        logger.debug((useLocalTime ? "LOCAL" : "REMOTE") + " machine time [" + time + "]: " + new Date(time));
    }
    return time;
}