- /**
- * 获取Date时间为本周的第几小时
- * @param currentDate
- * @return
- */
- public static Integer getHourOfWeekForDate(Date currentDate) {
- LocalDateTime localDateTime = LocalDateTime.ofInstant(currentDate.toInstant(), ZoneId.systemDefault());
- return getHourOfWeekForLocalDataTime(localDateTime);
- }
-
- /**
- * 获取LocalDateTime时间为本周的第几小时
- * @param now
- * @return
- */
- public static Integer getHourOfWeekForLocalDataTime(LocalDateTime now) {
- return (now.getDayOfWeek().getValue() - 1) * 24 + now.getHour() + 1;
- }
当前时间为周二的12点半时,输出为24+13=37,为什么加13,因为当前时间虽然是12点半,但是已经处于第13个小时内了。