获取网络时间

@PostMapping("/getTime")
public ResponseData getTime() throws IOException {
String webUrl = "http://www.baidu.com";
URL url=new URL(webUrl);
URLConnection conn=url.openConnection();
conn.connect();
long dateL=conn.getDate();
Date date=new Date(dateL);

SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String times = dateFormat.format(date);
return ResponseData.handleSuccess(times);
}
posted @ 2020-11-24 10:04  790021521  阅读(303)  评论(0编辑  收藏  举报