|
|
@ -9,6 +9,8 @@ import java.time.temporal.TemporalAdjusters; |
|
|
import java.util.Calendar; |
|
|
import java.util.Calendar; |
|
|
import java.util.Date; |
|
|
import java.util.Date; |
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.date.DateTime; |
|
|
|
|
|
import cn.hutool.core.date.DateUtil; |
|
|
import com.bnyer.common.core.enums.EnumTimeUnit; |
|
|
import com.bnyer.common.core.enums.EnumTimeUnit; |
|
|
import com.bnyer.common.core.enums.ResponseEnum; |
|
|
import com.bnyer.common.core.enums.ResponseEnum; |
|
|
import com.bnyer.common.core.exception.ServiceException; |
|
|
import com.bnyer.common.core.exception.ServiceException; |
|
|
@ -294,24 +296,25 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils |
|
|
return DateUtils.parseDate(format); |
|
|
return DateUtils.parseDate(format); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 判断当前时间是否在两个时间范围内 |
|
|
|
|
|
* @param startDate |
|
|
|
|
|
* @param endDate |
|
|
|
|
|
* @return |
|
|
|
|
|
*/ |
|
|
|
|
|
public static boolean isRang(Date startDate,Date endDate){ |
|
|
|
|
|
LocalDateTime startDateTime = LocalDateTime.ofInstant(startDate.toInstant(), java.time.ZoneId.systemDefault()); |
|
|
|
|
|
LocalDateTime endDateTime = LocalDateTime.ofInstant(endDate.toInstant(), java.time.ZoneId.systemDefault()); |
|
|
|
|
|
// 获取当前时间的LocalDateTime对象
|
|
|
|
|
|
LocalDateTime currentDateTime = LocalDateTime.now(); |
|
|
|
|
|
// 判断当前时间是否在开始和结束时间范围内
|
|
|
|
|
|
return currentDateTime.isAfter(startDateTime) && currentDateTime.isBefore(endDateTime); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
|
|
|
|
|
LocalDateTime now = LocalDateTime.now(); |
|
|
|
|
|
|
|
|
|
|
|
// 下个月的今天
|
|
|
|
|
|
LocalDateTime nextMonthToday = now.plusMonths(1); |
|
|
|
|
|
|
|
|
|
|
|
// 下一季度的今天
|
|
|
|
|
|
int currentMonth = now.getMonthValue(); |
|
|
|
|
|
int nextQuarterMonth = (currentMonth - 1) / 3 * 3 + (2 * 4); |
|
|
|
|
|
LocalDateTime nextQuarterToday = now.withMonth(nextQuarterMonth); |
|
|
|
|
|
|
|
|
|
|
|
// 下一年的今天
|
|
|
|
|
|
LocalDateTime nextYearToday = now.plusYears(1); |
|
|
|
|
|
|
|
|
|
|
|
System.out.println("下个月的今天:" + nextMonthToday.format(formatter)); |
|
|
public static void main(String[] args) { |
|
|
System.out.println("下一季度的今天:" + nextQuarterToday.format(formatter)); |
|
|
DateTime dateTime1 = DateUtil.parseDateTime("2023-05-18 00:00:00"); |
|
|
System.out.println("下一年的今天:" + nextYearToday.format(formatter)); |
|
|
DateTime dateTime2 = DateUtil.parseDateTime("2023-05-19 00:00:01"); |
|
|
|
|
|
System.out.println(isRang(dateTime1, dateTime2)); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|