sp0d不太正确:
timeInfo.getReturnTime(); // Returns time at which time message packet was received by local machine
所以它只是返回当前的系统时间,而不是收到的时间.见TimeInfo man page.
你应该使用
timeInfo.getMessage().getTransmitTimeStamp().getTime();
代替.
所以代码块将是:
String TIME_SERVER = "time-a.nist.gov";
NTPUDPClient timeClient = new NTPUDPClient();
InetAddress inetAddress = InetAddress.getByName(TIME_SERVER);
TimeInfo timeInfo = timeClient.getTime(inetAddress);
long returnTime = timeInfo.getMessage().getTransmitTimeStamp().getTime();
Date time = new Date(returnTime);