// 获得某天最大时间
public static Date getEndOfDay(Date date) {
LocalDateTime localDateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(date.getTime()), ZoneId.systemDefault());;
LocalDateTime endOfDay = localDateTime.with(LocalTime.MAX);
return Date.from(endOfDay.atZone(ZoneId.systemDefault()).toInstant());
}
// 获得某天最小时间
public static Date getStartOfDay(Date date) {
LocalDateTime localDateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(date.getTime()), ZoneId.systemDefault());
LocalDateTime startOfDay = localDateTime.with(LocalTime.MIN);
return Date.from(startOfDay.atZone(ZoneId.systemDefault()).toInstant());
}
/**
* 获取传过来的当天时间戳23:59:59的时间
*/
public static Long getDateEndMs(Long sampleTime) {
LocalDate todayDate = LocalDateTime.ofInstant(Instant.ofEpochMilli(sampleTime), ZoneId.systemDefault()).toLocalDate();
LocalDateTime beginTime = LocalDateTime.of(todayDate, LocalTime.MAX);
return LocalDateTime.from(beginTime).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
}
/**
* 获取一周以前的零点时刻 2021/3/26 11:28:00 ----> 2021/3/19 00:00:00
*/
public static Long getRecentWeekUserCount(Long sampleTime) {
LocalDate today = LocalDateTime.ofInstant(Instant.ofEpochMilli(sampleTime), ZoneId.systemDefault()).toLocalDate();
LocalDate nextWeek = today.plus(-1, ChronoUnit.WEEKS);
return nextWeek.atStartOfDay(ZoneId.systemDefault()).toInstant().toEpochMilli();
}
/**
* 获取一个月以前那天的零点
*
* @return
*/
public static Long getMonthAgo(){
LocalDateTime beginTime = LocalDateTime.of(LocalDate.now(), LocalTime.MIN);
LocalDateTime date = beginTime.minusMonths(1);
return LocalDateTime.from(date).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
}