问题遇到的现象和发生背景 写了一个通过socket获取苏宁接口的程序把显示时间的那部分提出来了,但是数据是固定的想让那个时间动起来相当于每秒更新一次的那种效果该怎么写
用代码块功能插入代码,请勿粘贴截图
public void Socketclient (){
new Thread(()-> {
try {
socket = new Socket("quan.suning.com", 80);
Log.e("HTTPclientjson", "socket创建实例");
String request = "GET /getSysTime.do HTTP/1.1\r\n" +//请求行
"Host: quan.suning.com:80\r\n" + "\r\n";//请求头
printWriter = new PrintWriter(socket.getOutputStream(), true);
printWriter.println(request);
Log.e("HTTPclientjson", "发送输出流:" + request);
inputStream = socket.getInputStream();
if(inputStream!=null){
Log.e("HTTPclientjson", "输入流不为空" );
while (bool){
byte[] bytes= new byte[1024];
try {
inputStream.read(bytes);
} catch (IOException e) {
e.printStackTrace();
}
String data= new String(bytes, StandardCharsets.UTF_8).trim();
Log.e("HTTPclientjson", "输入流:" + data);
Systime(data);
bool=false;
}
}
} catch (IOException e) {
e.printStackTrace();
}
}).start();
}
private void Systime(String str){
if(str.contains("sysTime1")){
int i =str.indexOf("sysTime1");
if(i+25<=str.length()){
String time = str.substring(i + 11, i + 11 + 14);
Log.e("HTTPclientjson", "得到时间:" + time);
}
}
}