import java.time.LocalTime;
public class StringTimeExample {
public static String timeUtils(String timeData){
LocalTime currentTime = LocalTime.parse(timeData);
int timePeriodLength = 2;
int periodIndex = currentTime.getHour() / timePeriodLength;
LocalTime periodStart = LocalTime.of(periodIndex * timePeriodLength, 0);
LocalTime periodEnd = periodStart.plusHours(timePeriodLength);
System.out.println("当前时间 " + timeData + " 属于时间段:" + periodStart + "-" + periodEnd);
return periodStart + "-" + periodEnd;
}
public static void main(String[] args) {
timeUtils("21:39");
}
}