如何检查当前时间和自定义时间是否在 30 分钟的设备时隙(挂钟时间)内

How do I check if current time and a custom time are within device time slot (wall clock time) of 30 mins

我有一个独特的问题,我必须确定两件事。

1) 如果我的当前时间和自定义时间在同一个 30 分钟时间段内(比如说它的 2:10pm 并且自定义时间是 2:22pm ,我想看到它们在从 2 到 2:30 的同一时间段)但如果当前时间为 1:55pm 且自定义时间为 2:15pm 则不应在同一时间段(相差 30 分钟但不在同一时间段内 device/clock 时间段,一个是 1:30 到下午 2 点,另一个是 2 点到 2:30 下午)

2) 现在,在 30 分钟的同一时间段内,如果当前时间早于自定义时间,我想 return 为真,否则 return 为假。有什么办法可以计算这个? 我想在我的常用工具 class 中添加一个自定义函数,我可以在其中输入自定义时间和当前时间并查看结果,因此拥有一些通用的东西会很有用。 有什么想法吗?

我看过:Check if a given time lies between two times regardless of date 和其他文章,但没有描述 30 分钟 device/clock 时间段。

知道 https://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/time/DateUtils.html 是否会以某种方式帮助我操纵这个确切的逻辑,或者 android 中的任何自定义 function/library 对此有所帮助。真的很有帮助!

package Demo;

import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.Arrays;
public class Test1 {
    public static void main(String arg[]) {
        LocalDateTime ct = LocalDateTime.now();
        LocalDateTime custemTime = ct.plusMinutes(5);
        System.out.println(ct);
        System.out.println(custemTime)  ;
        System.out.println(isInSameSlots(ct,custemTime));

    }   
    static boolean   isInSameSlots(LocalDateTime ldt1, LocalDateTime ltd2) {
        Long timeDiff = ChronoUnit.MINUTES.between(ldt1, ltd2);
        if(timeDiff > 30 || timeDiff < 0) 
           return false;
        return (ldt1.getMinute() <= 30 && ltd2.getMinute() <= 30) || (ldt1.getMinute() > 30 && ltd2.getMinute() > 30 ) ? true : false; 

    }

}

案例 1

2019-06-10T18:40:09.122

2019-06-10T18:45:09.122

正确

案例二) 2019-06-10T18:46:56.350 2019-06-10T19:06:56.350 假