我正在使用以下代码从Android设备的AtomicTime服务器连接并检索UTC时间:
public static final String ATOMICTIME_SERVER="http://132.163.4.101:13";
BufferedReader in = null;
try
{
URLConnection conn = new URL(ATOMICTIME_SERVER).openConnection();
in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String atomicTime;
while (true)
{
if ( (atomicTime = in.readLine()).indexOf("*") > -1)
{
break;
}
}
... do something
}
catch ...
它不返回任何数据。从浏览器访问URL时,我们得到以下信息:
55884 11-11-19 07:40:22 00 0 0 824.5 UTC(NIST)
有人可以帮忙吗?
最佳答案
String atomicTime = "";
try
{
Socket socket = new Socket("132.163.4.101", 13);
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
in.readLine(); // Ignore leading blank line
atomicTime = in.readLine();
socket.close();
}
catch....