前端传到后端的时间间隔是 2022-08-13 00:00:00 - 2022-08-13 23:59:59
后端接收到的是一个字符串,那么后端如何变为date类型
filterTime 值为 2022-08-13 00:00:00 - 2022-08-13 23:59:59
// parse param
Date triggerTimeStart = null;
Date triggerTimeEnd = null;
if (filterTime!=null && filterTime.trim().length()>0) {
String[] temp = filterTime.split(" - ");
if (temp.length == 2) {
triggerTimeStart = DateUtil.parseDateTime(temp[0]);
triggerTimeEnd = DateUtil.parseDateTime(temp[1]);
}
}
时间工具类
private static final String DATETIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
/**
* parse datetime string, like "yyyy-MM-dd HH:mm:ss"
*将字符串 类型的日期 转为 Date 类型
* @param dateString
* @return
* @throws ParseException
*/
public static Date parseDateTime(String dateString) {
return parse(dateString, DATETIME_FORMAT);
}