2015-11-07 62 views

回答

0

看来,不过已经有了类似的问题在这里:How to use an Internet time server to get the time?

我必须承认我没有本人来说用这个,但它看起来就像是值得一试。它使用apache commons库。

复制相关代码(链接完整说明):

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); 

东西不说存在该TIME_SERVER可能不会更新。下面是与它们的可用性服务器的列表:http://tf.nist.gov/tf-cgi/servers.cgi#

请让我知道,如果这个工作对你:)

0

你需要自己检查一下,使用SNTP客户端或其他东西。

即使用户没有手动更改时间,也不要求设备使用“Internet”自动设置时间。例如,美国的许多设备依靠无线运营商的NITZ信号作为其时间源。

+0

我试过,但我使用有问题的HttpClient –