Date startQxsDate = custPlanQxsForm.getStartQxsDate(); Date endQxsDate = custPlanQxsForm.getEndQxsDate();java后端校验结束时间必须大于开始时间
时间: 2024-01-02 15:02:31 浏览: 12
是的,你的代码中使用了两个 Date 类型的变量 startQxsDate 和 endQxsDate,需要对这两个日期进行比较,确保 endQxsDate 大于 startQxsDate。可以使用如下代码进行校验:
```
if (endQxsDate.before(startQxsDate)) {
// 结束时间早于开始时间,校验不通过
// 进行相应的处理
} else {
// 校验通过
// 进行相应的处理
}
```
其中,before() 方法是判断一个日期是否在另一个日期之前的方法。
相关问题
Date now = cal.getTime(); java实现把now转换为String
可以使用SimpleDateFormat类来将Date类型转换为String类型。以下是示例代码:
```java
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class Test {
public static void main(String[] args) {
Calendar cal = Calendar.getInstance();
Date now = cal.getTime();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String strDate = sdf.format(now);
System.out.println(strDate);
}
}
```
输出结果为当前时间的字符串形式,例如:"2021-06-01 14:30:00"。其中,SimpleDateFormat类的参数可以根据需要自行调整。
Date reportUpdateAtFrom = request.getReportUpdateAtFrom(); //将时间提前八个小时转换 需要返回Date对象
可以使用`java.util.Calendar`类来将时间提前八个小时。具体代码如下:
```
Date reportUpdateAtFrom = request.getReportUpdateAtFrom();
Calendar calendar = Calendar.getInstance();
calendar.setTime(reportUpdateAtFrom);
calendar.add(Calendar.HOUR_OF_DAY, -8);
Date newDate = calendar.getTime();
return newDate;
```
这样就可以将`reportUpdateAtFrom`时间提前八个小时,并返回一个`Date`对象。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)