java 获取当前月份上一个月1号0点和当前月份下一个月月底24点 返回Date()
时间: 2023-04-01 13:04:17 浏览: 122
可以使用以下代码实现:
```java
import java.util.Calendar;
import java.util.Date;
public class Main {
public static void main(String[] args) {
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.MONTH, -1);
calendar.set(Calendar.DAY_OF_MONTH, 1);
calendar.set(Calendar.HOUR_OF_DAY, );
calendar.set(Calendar.MINUTE, );
calendar.set(Calendar.SECOND, );
Date lastMonthFirstDay = calendar.getTime();
calendar = Calendar.getInstance();
calendar.add(Calendar.MONTH, 1);
calendar.set(Calendar.DAY_OF_MONTH, 1);
calendar.set(Calendar.HOUR_OF_DAY, );
calendar.set(Calendar.MINUTE, );
calendar.set(Calendar.SECOND, );
calendar.add(Calendar.SECOND, -1);
Date nextMonthLastDay = calendar.getTime();
System.out.println("上个月1号点:" + lastMonthFirstDay);
System.out.println("下个月月底24点:" + nextMonthLastDay);
}
}
```
阅读全文