如何获取java中不同时间服务器的当前时间?

时间:2012-04-06 09:55:00

标签: java android

我有三个时间服务器,time-nw.nist.gov,time1.ucla.edu,time.ien.it 现在我怎样才能获得java / android中所有这个服务器的当前时间?

1 个答案:

答案 0 :(得分:1)

检查Apache Commons Net库

https://commons.apache.org/net/

来自example

public static final void timeTCP(String host) throws IOException
{
    TimeTCPClient client = new TimeTCPClient();
    try {
          // We want to timeout if a response takes longer than 60 seconds
          client.setDefaultTimeout(60000);
          client.connect(host);
          System.out.println(client.getDate());
    } finally {
          client.disconnect();
    }
}