[android]代码库
new Thread(new Runnable() {
@Override
public void run() {
try {
URL url = new URL("http://bjtime.cn/");// 取得资源对象
URLConnection uc = url.openConnection();// 生成连接对象
uc.setConnectTimeout(2000);
uc.connect(); // 发出连接
Calendar calendar = Calendar.getInstance();
long timeStamp = uc.getDate();
calendar.setTimeInMillis(timeStamp);
// 重置计时时间
if (null != ServerService.getInstance()) {
ServerService.getInstance().resetHeartBeatAckTime(timeStamp);
ServerService.getInstance().resetHeartBeatSendTime(timeStamp);
ServerService.getInstance().resetRetryServerConnectTime(timeStamp);
}
String command = String.format("date -s %d%02d%02d.%02d%02d%02d", calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1, calendar.get(Calendar.DAY_OF_MONTH), calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), calendar.get(Calendar.SECOND));
GlobalMethod.execShell(command);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}).start();