gpt4 book ai didi

Java比较一天中自定义开始结束时间的两次

转载 作者:行者123 更新时间:2023-12-02 06:07:17 25 4
gpt4 key购买 nike

我收到两次(格式为 HH:mm aa),即下午 6:00 到下午 5:00。我需要一些通用且最短的方法来比较这两个时间。

例如:-

假设我正在比较下午 4 点和下午 7 点,那么我应该得到下午 4 点 > 晚上 7 点,因为我的开始时间是下午 6 点,结束时间是下午 5 点

请帮忙。

最佳答案

         // Per the JavaDoc:
// the value 0 if the argument Date is equal to this Date; a value
// less than 0 if this
// Date is before the Date argument; and a value greater
// than 0 if this Date is after
// the Date argument.

if (startDate.compareTo(endDate) < 0)
{
// before
}
else if (startDate.compareTo(endDate) == 0)
{
// same
}
else if (startDate.compareTo(endDate) > 0)
{
// after
}
else if (startDate.compareTo(firstDate) > 0 && startDate.compareTo(secondDate) < 0)
{
// between
}

根据需要插入您的条件。

关于Java比较一天中自定义开始结束时间的两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22172377/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com