|
|
@@ -3,11 +3,9 @@ package Utils;
|
|
|
import com.google.gson.JsonObject;
|
|
|
import com.nju.edu.logTracking.enums.SeecSystem;
|
|
|
|
|
|
-import java.io.IOException;
|
|
|
-import java.net.URL;
|
|
|
-import java.net.URLConnection;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
-import java.util.Date;
|
|
|
+import java.time.ZoneId;
|
|
|
+import java.util.TimeZone;
|
|
|
|
|
|
public class LogBuilder {
|
|
|
private final JsonObject log = new JsonObject();
|
|
|
@@ -40,22 +38,13 @@ public class LogBuilder {
|
|
|
log.addProperty("message", message);
|
|
|
return this;
|
|
|
}
|
|
|
- private String getTimeByWeb(){
|
|
|
- try {
|
|
|
- URL url=new URL("https://baidu.com");
|
|
|
- URLConnection conn=url.openConnection();
|
|
|
- conn.connect();
|
|
|
- long dateL=conn.getDate();
|
|
|
- Date date=new Date(dateL);
|
|
|
- SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
|
|
- return dateFormat.format(date);
|
|
|
- } catch (IOException e) {
|
|
|
- return "无法获取时间";
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
public String build() {
|
|
|
- log.addProperty("created_time", getTimeByWeb());
|
|
|
+ SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ TimeZone timeZone = TimeZone.getTimeZone(ZoneId.of("+8"));
|
|
|
+ formatter.setTimeZone(timeZone);
|
|
|
+ String dateString = formatter.format(System.currentTimeMillis());
|
|
|
+ log.addProperty("created_time", dateString);
|
|
|
return log.toString();
|
|
|
}
|
|
|
}
|