/**
* 获取当月开始时间和结束时间
* @return 起止时间
*/
public static Date[] getMonthRangeDate() {
LocalDate today = LocalDate.now();
//本月的第一天
LocalDate firstDay = LocalDate.of(today.getYear(), today.getMonth(), 1);
Date startTimeInMonth = Date.from(firstDay.atStartOfDay(ZoneOffset.ofHours(8)).toInstant());
//本月的最后一天
LocalDate lastDay = today.with(TemporalAdjusters.lastDayOfMonth());
Date endTimeInMonth = Date.from(lastDay.atStartOfDay(ZoneOffset.ofHours(8)).toInstant());
return new Date[]{getDayStartTime(startTimeInMonth),getDayEndTime(endTimeInMonth)};
}
/**
* 获取某个日期的开始时间
* @return 起止时间
*/
public static Date getDayStartTime(Date d) {
Calendar calendar = Calendar.getInstance();
if(null != d) {calendar.setTime(d);}
calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_O
jdk 1.8 获取本月开始时间和结束时间
最新推荐文章于 2023-04-25 18:32:04 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)