gpt4 book ai didi

java - 日历 <= 另一个日历

转载 作者:行者123 更新时间:2023-12-01 06:40:25 27 4
gpt4 key购买 nike

while (r.next()) {
String rn = r.getString(3);
String sqldate = r.getString(2); // database reservation date
}

从数据库获取日期

DateFormat RD = new SimpleDateFormat("yyyy-MM-dd");
java.sql.Date converteddate = new java.sql.Date(RD.parse(sqldate).getTime());
Calendar cal = Calendar.getInstance();
Calendar cal1 = Calendar.getInstance();
cal.setTime(converteddate);
cal.add(Calendar.DATE, 7);
if(cal<=cal1){ }// i need to this opration i dont know how

我需要检查 cal 是否 <= Cal1。有什么想法吗?

最佳答案

日历是可比较的,您可以使用 Calendar#compareTo() method :

compareTo returns the value 0 if the time represented by the argument is equal to the time represented by this Calendar; a value less than 0 if the time of this Calendar is before the time represented by the argument; and a value greater than 0 if the time of this Calendar is after the time represented by the argument

在您的情况下,要确定 cal 是否早于或等于 cal1,您可以使用:

if (cal.compareTo(cal1) <= 0) {}

关于java - 日历 <= 另一个日历,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12950279/

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