between java.time.LocalTime (next day)

前端 未结 3 1800
孤街浪徒
孤街浪徒 2021-01-04 13:59

Please suggest if there is an API support to determine if my time is between 2 LocalTime instances, or suggest a different approach.

I have this entity:

3条回答
  •  臣服心动
    2021-01-04 14:32

    I have refactored @assylias answer so i use int instead of local time as i get open and close hour from api int integer format

    public static boolean isOpen(int start, int end, int time) {
        if (start>end) {
            return time>(start) || time<(end);
        } else {
            return time>(start) && time<(end);
        }
    }
    public static boolean isOpen(int start, int end) {
        SimpleDateFormat sdf = new SimpleDateFormat("HH");
        Date resultdate = new Date();
        String hour = sdf.format(resultdate);
        int time = Integer.valueOf(hour);
        if (start>end) {
            return time>(start) || time<(end);
        } else {
            return time>(start) && time<(end);
        }
    }
    

提交回复
热议问题