package com.zanxiang.common.utils; import com.zanxiang.module.util.DateUtil; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; import java.time.temporal.TemporalAdjusters; /** * 时间工具类 * * @author ruoyi */ public class DateUtils extends DateUtil { /** * 验证当前时间是否为当天 * * @param time * @return */ public static boolean isToday(LocalDateTime time) { LocalDateTime startTime = LocalDateTime.now().with(LocalTime.MIN); LocalDateTime endTime = LocalDateTime.now().with(LocalTime.MAX); //如果大于今天的开始日期,小于今天的结束日期 return time.isAfter(startTime) && time.isBefore(endTime); } /** * 验证当前时间是否为当月 * * @param time * @return */ public static boolean isThisMonth(LocalDateTime time) { LocalDate localDate = time.toLocalDate(); LocalDate now = LocalDate.now(); return localDate.isAfter(now.minusMonths(1).with(TemporalAdjusters.lastDayOfMonth())) && localDate.isBefore(now.plusMonths(1).with(TemporalAdjusters.firstDayOfMonth())); } /** * 验证当前时间是否为本周 * * @param time * @return */ public static boolean isThisWeek(LocalDateTime time) { LocalDateTime now = LocalDateTime.now(); int dayOfWeek = now.getDayOfWeek().getValue(); LocalDateTime weekStart = now.minusDays(dayOfWeek - 1).with(LocalTime.MIN); LocalDateTime weekEnd = now.plusDays(7 - dayOfWeek).with(LocalTime.MAX); return time.isAfter(weekStart) && time.isBefore(weekEnd); } }