任意一天中起始时间和结束时间
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());
}
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 getZero() throws ParseException {
return new SimpleDateFormat(DATE_TIME_PATTERN).parse(DateFormatUtils.format(new Date(), "yyyy-MM-dd 00:00:00"));
}
public static Date getEnd() throws ParseException {
return new SimpleDateFormat(DATE_TIME_PATTERN).parse(DateFormatUtils.format(new Date(), "yyyy-MM-dd 23:59:59"));
}
public static String getWeek(Date date) {
String[] weeks = {"周日", "周一", "周二", "周三", "周四", "周五", "周六"};
Calendar cal = Calendar.getInstance();
cal.setTime(date);
int week_index = cal.get(Calendar.DAY_OF_WEEK) - 1;
if (week_index < 0) {
week_index = 0;
}
return weeks[week_index];
}