Question: The time difference between international standard time (front desk) and year, month and day is 8 hours. If you use String, the date obtained will be eight hours shorter.
(Reason: Universal time is standard. Beijing time is 8 hours ahead of universal time)
If the background uses the following to receive the front-end code
//Before modification, you will find that the obtained time is eight hours less than expected @TableField(exist = false) @ApiModelProperty(value = "Upload date (from), used for query") private String syncTimeStart;
should be changed to
//After modification: The time difference between international standard time (front desk) and year, month and day is 8 hours. If you use String, the date obtained will be eight hours less @TableField(exist = false) @ApiModelProperty(value = "Upload date (starting), Query using ") private Date syncTimeStart;
req.setSyncTimeStart(StrUtils.dateTimeChange(req.getSyncTimeStart(),"00:00:00")); req.setSyncTimeEnd(StrUtils.dateTimeChange(req.getSyncTimeEnd(),"23:59:59"));
public static Date dateTimeChange (Date date, String time) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String formatStr = sdf.format(date);
formatStr = formatStr.substring(0,10)+" "+time;
Date changeDate = null;
try {
changeDate = sdf.parse(formatStr);
} catch (ParseException e) {
e.printStackTrace();
}
return changeDate;
}
Of course, you can also use two time conversion methods to solve the problem